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 combine duplicates, but summarize their contributions. The result will look like this:
var arr = [ { name: 'John', contributions: 3 }, { name: 'Mary', contributions: 5 } ];
How can I achieve this using JavaScript?
source share