title: Merge objects in array by value and get count for each
body: <p>Given the following array of objects:</p>
  
  <pre><code>myArray = [
    {
      item: 'Item 1',
      material: 'Material1',
      type: 'head'
    },
    {
      item: 'Item 1',
      material: 'Material1',
      type: 'head'
    },
    {
      item: 'Item 2',
      material: 'Material2',
      type: 'shell'
    },
    {
      item: 'Item 1',
      material: 'Material1',
      type: 'head'
    },
    {
      item: 'Item 2',
      material: 'Material2',
      type: 'shell'
    },
    {
      item: 'Item 3',
      material: 'Material3',
      type: 'support'
    },
    {
      item: 'Item 1',
      material: 'Material1',
      type: 'head'
    },
    {
      item: 'Item 3',
      material: 'Material3',
      type: 'support'
    },
    {
      item: 'Item 2',
      material: 'Material2',
      type: 'shell'
    }
  ]
  </code></pre>
  
  <p>I need to combine these by the <code>item</code> value with a count so that I get an array that looks like this:</p>
  
  <pre><code>var myResultArray = [
    {
      item: 'Item 1',
      material: 'Material1',
      type: 'head'
      count: 4
    },
    {
      item: 'Item 2',
      material: 'Material2',
      type: 'shell'
      count: 3
    },
    {
      item: 'Item 3',
      material: 'Material3',
      type: 'support'
      count: 2
    },
  ]
  </code></pre>
  
  <p>What is the easiest way to do this? I'm partial to Lodash, but I'm open to other alternatives. With <code>_.groupBy()</code> I can get everything grouped together with the item as the object key:</p>
  
  <pre><code>var myGrouped = _.groupBy(myArray, 'item');
  </code></pre>
  
  <p>but that only gets me part way there. Searching around here I see a lot of uses of <code>_.reduce()</code> (or just plain <code>.reduce()</code>) or <code>_.map()</code>, but I haven't been able to get my head around exactly how to use them in this case. If I try to use <code>_.groupBy()</code> chained with <code>_.map()</code> like so</p>
  
  <pre><code>var myGrouped = _(myArray).groupBy('item').map(function(item) {
                    // do stuff here
                  });
  </code></pre>
  
  <p>the execution doesn't even get to my map function, so I'm not sure what I'm doing wrong.</p>
  
  <p>Thanks.</p>