[Solved] sum numeric values in a multidimentional array


Just:

var scores = [{
  "firstName": "John",
  "value": 89
}, {
  "firstName": "Peter",
  "value": 151
}, {
  "firstName": "Anna",
  "value": 200
}, {
  "firstName": "Peter",
  "value": 22
}, {
  "firstName": "Anna",
  "value": 60
}];

var names = {};
var new_arr = [];

scores.forEach(function(entry) {
  if (names.hasOwnProperty(entry.firstName)) {
    new_arr[names[entry.firstName]].value += entry.value;
  } else {
    names[entry.firstName] = new_arr.length;
    new_arr.push({
      "firstName": entry.firstName,
      "value": entry.value
    });
  }
});

console.log(new_arr);

3

solved sum numeric values in a multidimentional array