title: convert object keys and values to an array of objects
body: <p>I have an object that looks like this:</p>
  
  <pre><code>const response = {
    id1-field1: true,
    id1-field2: 0,
    id1-field3: 3,
    id2-field1: false,
    id2-field2: 1,
    id2-field3: 0,
    id3-field1: false,
    id3-field2: 0,
    id3-field3: 0,
  }
  </code></pre>
  
  <p>And I need to make an array that looks like this:</p>
  
  <pre><code>const formatted = [
   {id: "id1", field1: true, field2: 0, field3: 3},
   {id: "id2", field1: false, field2: 1, field3: 0},
   {id: "id3", field1: false, field2: 0, field3: 0},
  ]
  </code></pre>
  
  <p>What's the best way to achieve this? This is where I'm at so far:</p>
  
  <ol>
  <li>Get the object's keys in an array</li>
  <li>Split the object keys by the hyphen</li>
  <li>Use the original keys to add in the object values</li>
  </ol>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const response = {
    "id1-field1": true,
    "id1-field2": 0,
    "id1-field3": 3,
    "id2-field1": false,
    "id2-field2": 1,
    "id2-field3": 0,
    "id3-field1": false,
    "id3-field2": 0,
    "id3-field3": 0,
  }
  
  const keys = Object.keys(response)
  
  const split = keys.map(x =&gt; { 
    return ({"oldId": x, "id": x.split('-')[0], "key": x.split('-')[1]})
  })
  
  const splitWithValues = split.map( x =&gt; {
      let o = x;
      o.value = response[x.oldId]
      return o
  })
  
  console.log(splitWithValues)</code></pre>
  </div>
  </div>
  </p>