title: How to group by and sum an array of objects?
body: <p>I would like to group an array of objects by <code>Id</code> and sum the quantity in jQuery. How can I achieve this?</p>
  <p>For example:</p>
  <pre><code>var array = [
    { Id: &quot;001&quot;, qty: 1 },
    { Id: &quot;002&quot;, qty: 2 },
    { Id: &quot;001&quot;, qty: 2 },
    { Id: &quot;003&quot;, qty: 4 }
  ]
  </code></pre>
  <p>Should result in:</p>
  <pre><code>[
    { Id: &quot;001&quot;, qty: 3 },
    { Id: &quot;002&quot;, qty: 2 },
    { Id: &quot;003&quot;, qty: 4 }
  ]
  </code></pre>