title: Sum JavaScript object propertyA values with the same object propertyB in an array of objects
body: <p>How would one take a JavaScript array of objects, such as</p>
  <pre class="lang-js prettyprint-override"><code>objArr = [
      {key:&quot;Mon Sep 23 2013 00:00:00 GMT-0400&quot;, val:42},
      {key:&quot;Mon Sep 24 2013 00:00:00 GMT-0400&quot;, val:78},
      {key:&quot;Mon Sep 25 2013 00:00:00 GMT-0400&quot;, val:23},
      {key:&quot;Mon Sep 23 2013 00:00:00 GMT-0400&quot;, val:54} // &lt;- duplicate key
  ]
  </code></pre>
  <p>and merge duplicate keys by summing the values?</p>
  <p>In order to get something like this:</p>
  <pre><code>reducedObjArr = [
      {key:&quot;Mon Sep 23 2013 00:00:00 GMT-0400&quot;, val:96},
      {key:&quot;Mon Sep 24 2013 00:00:00 GMT-0400&quot;, val:78},
      {key:&quot;Mon Sep 25 2013 00:00:00 GMT-0400&quot;, val:23}
  ]
  
  </code></pre>
  <p>I have tried iterating and adding to a new array, but this didn't work:</p>
  <pre><code>var reducedObjArr = [];
  var item = null, key = null;
  for(var i=0; i&lt;objArr.length; i++) {
      item = objArr[i];
      key = Object.keys(item)[0];
      item = item[key];
  
      if(!result[key]) {
          result[key] = item;
      } else {
         result[key] += item;
      }
  }a
  </code></pre>