1
I’m doing a job and I came across a question that is apparently quite simple, but I’m not getting it. I need to do a reduce
(or could be otherwise as well) to sum the quantity of items with the identical property. For example:
let arr = [
{id: "xxx", amount: 2},
{id: "xxx", amount: 7},
{id: "yyy", amount: 2},
{id: "yyy", amount: 5},
{id: "zzz", amount: 5}
];
For this Array
above, I would need to get the following result:
[
{id: "xxx", amount: 9},
{id: "yyy", amount: 7},
{id: "zzz", amount: 5}
]
It helped a lot. The two codes are brilliant.
– Mr Genesis