【发布时间】:2020-12-04 16:05:29
【问题描述】:
我需要合并价格相同的对象并添加数量(amount)。
例子:
[
{price: 25.1, amount: 32},
{price: 45.2, amount: 45},
{price: 25.1, amount: 25},
{price: 44.0, amount: 13},
{price: 45.2, amount: 23}
]
结果:
[
{price: 25.1, amount: 57}, // 32 + 25
{price: 45.2, amount: 68}, // 45 + 23
{price: 44.0, amount: 13},
]
【问题讨论】:
标签: javascript arrays