I have been trying to combine objects inside an array with same id-value. The array that I have is like this:
[ {\"id\" : \"abcd\",\"val1\" : 1,\"val2\": 1,
This should do it with underscore's functional approach:
_.map(_.groupBy(arr, "id"), function(vals, id) { return _.reduce(vals, function(m, o) { for (var p in o) if (p != "id") m[p] = (m[p]||0)+o[p]; return m; }, {id: id}); });