Input array
[{ id: 1, title: 'shirt', price: 2000 },
{ id: 2, title: 'shirt', price: 4000},
{ id: 3, title: 'tshirt', price: 10000}]
Expected output
[{ id: 1, title: 'shirt', price: 6000 }, // 2000 + 4000
{ id: 3, title: 'tshirt', price: 10000}]
Have tried multiple ways to achieve but couldn't get a solution.
I'm able to get unique objects but need the addition of price as well
let result = products.filter((product, index, self) =>
index === self.findIndex((t) => (t.title === product.title))
)
console.log(result);
id? should it take the first one?