title: How to group an array of objects in JavaScript on specific fields using Lodash?
body: <p><strong>EDIT:</strong>
  I believe this is a different problem than a simple <code>_.groupBy</code> because I am trying to group by all keys and returning an hashmap not an array.</p>
  
  <hr>
  
  <p>I have an array of the following objects:</p>
  
  <pre><code>items = [
    { created_at: "01/01/2016", name: "bob", age: 21, height: 60 },
    { created_at: "01/02/2016", age: 22, height: 70 },
    { created_at: "01/03/2016", name: "alice", age: 23 }
  ]
  </code></pre>
  
  <p>And I am trying to transform it into this format:</p>
  
  <pre><code>{
    "name": [
      {
        "value": "bob",
        "created_at": "01/01/2016"
      },
      {
        "value": "alice",
        "created_at": "01/03/2016"
      }
    ],
    "age": [
      {
        "value": 21,
        "created_at": "01/01/2016"
      },
      {
        "value": 22,
        "created_at": "01/02/2016"
      },
      {
        "value": 23,
        "created_at": "01/03/2016"
      }
    ],
    "height": [
      {
        "value": 60,
        "created_at": "01/01/2016"
      },
      {
        "value": 70,
        "created_at": "01/02/2016"
      }
    ]
  }
  </code></pre>
  
  <p>My requirement is I am ignoring the <code>created_at</code> field, but grouping everything else.</p>
  
  <p>One solution is:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var items = [
    { created_at: "01/01/2016", name: "bob", age: 21, height: 60 },
    { created_at: "01/02/2016", age: 22, height: 70 },
    { created_at: "01/03/2016", name: "alice", age: 23 }
  ]
  
  var store = {}
  for(var i=0; i &lt; items.length; i++) {
    var item = items[i]
    
    for(key in item) {
      if(key === "created_at") {
        continue
      }
      
      value = item[key]
  
      if(!store[key]) {
        store[key] = []
      }
  
      store[key].push({
        value: value,
        created_at: item.created_at
      })
    }
  }
  
  $('pre').text(JSON.stringify(store, null, 2))</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;body&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I was wondering if there was some cool way to do it in <code>lodash</code> ... maybe using <code>.map()</code> or <code>.groupBy()</code> or something? I don't quite get how to use them properly and am trying to learn new, more elegant ways to write the code.</p>