Answers for "sum elements in list with same name js"

0

sum elements in list with same name js

let traveler = [{"description":"Senior","Amount":50},{"description":"Senior","Amount":50},{"description":"Adult","Amount":75},{"description":"Child","Amount":35},{"description":"Infant","Amount":25}]

let result = traveler.reduce((c, v) => {
  c[v.description] = (c[v.description] || 0) + v.Amount;
  return c;
}, {});

console.log(result);
Posted by: Guest on June-08-2020

Code answers related to "sum elements in list with same name js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language