title: How to fill in missing keys in an Array of Objects?
body: <p>I have an Array of Objects which should all have the same keys, but some of the keys are missing. I would like to fill in the missing keys with a generic value.</p>
  
  <p>I am looking for a simple way to do that (natively or via a library), the code below I use now works, bit looks to my untrained eyes quite heavy and I am sure I reinvented the tedious way to do something while there is a simple one.</p>
  
  <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>var arr = [{
      "a": 1,
      "b": 2,
      "c": 3
    },
    {
      "a": 10,
      "c": 30
    },
    {
      "b": 200,
      "c": 300
    },
  ]
  // get the list of all keys
  var allkeys = []
  arr.forEach((objInArr) =&gt; {
    allkeys = allkeys.concat(Object.keys(objInArr))
  })
  // check all arr entries for missing keys
  arr.forEach((objInArr, i) =&gt; {
    allkeys.forEach((key) =&gt; {
      if (objInArr[key] === undefined) {
        // the generic value, in this case 0
        arr[i][key] = 0
      }
    })
  })
  console.log(arr)</code></pre>
  </div>
  </div>
  </p>