📌  相关文章
📜  将列表中具有相同名称js的元素相加 - Javascript代码示例

📅  最后修改于: 2022-03-11 15:02:55.798000             🧑  作者: Mango

代码示例1
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);