title: Convert array of objects to an object of arrays
body: <p>I have the following structure</p>
  
  <pre><code>var nights = [
      { "2016-06-25": 32, "2016-06-26": 151, "2016-06-27": null },
      { "2016-06-24": null, "2016-06-25": null, "2016-06-26": null },
      { "2016-06-26": 11, "2016-06-27": 31, "2016-06-28": 31 },
  ];
  </code></pre>
  
  <p>And I want to transform it to:</p>
  
  <pre><code>{ 
      "2016-06-24": [null], 
      "2016-06-25": [32, null], 
      "2016-06-26": [151, null, 11], 
      "2016-06-27": [null, 31], 
      "2016-06-28": [31] 
  }
  </code></pre>
  
  <p>What's the shortest way to solve this? I have no problems with using Underscore, Lodash or jQuery.</p>
  
  <p>My current code is:</p>
  
  <pre><code>var out = {};
  for (var i = 0; i &lt; nights.length; i++) {
      for (var key in nights[i]) {
          if (out[key] === undefined) {
              out[key] = [];
          }
          out[key].push(nights[i][key]);
      }
  }
  </code></pre>
  
  <p>It's similar to <a href="https://stackoverflow.com/questions/36638450/convert-array-of-objects-to-object-of-arrays-using-lodash">Convert array of objects to object of arrays using lodash</a> but that has all keys present in each object.</p>