var sales = [
{
order_id: 138,
price: 25,
},
{
order_id: 138,
price: 30,
},
{
order_id: 139,
price: 15,
},
{
order_id: 131,
price: 25,
},
];
var buf = {}
sales.map(obj => {
if(buf[obj.order_id]) {
buf[obj.order_id].price += obj.price
} else {
buf[obj.order_id] = obj
}
})
var result = Object.values(buf)
console.log(result)
1
solved Merging objects by property, accumulating another property in node