35
rated 0 times
[
36]
[
1]
/ answers: 1 / hits: 18303
/ 8 Years ago, sun, july 10, 2016, 12:00:00
I have this array of objects:
var arr = [
{
name: 'John',
contributions: 2
},
{
name: 'Mary',
contributions: 4
},
{
name: 'John',
contributions: 1
},
{
name: 'Mary',
contributions: 1
}
];
... and I want to merge duplicates but sum their contributions. The result would be like the following:
var arr = [
{
name: 'John',
contributions: 3
},
{
name: 'Mary',
contributions: 5
}
];
How could I achieve that with JavaScript?
More From » arrays