a = [
{val1: 1, val2: 1},
{val1: 2, val2: 2},
{val1: 3, val2: 3}
];
var a = [
{val1: 1, val2: 1},
{val1: 2, val2: 2},
{val1: 3, val2: 3}
];
function sumProps (arr) {
var out = {};
arr.forEach(function(i) {
for (var p in i) {
if (i.hasOwnProperty(p)) {
out[p] = out[p] || 0;
out[p] += i[p];
}
}
});
return out;
}
console.log(sumProps (a));