I have an array of objects, and I'm trying to sum the value of the amount property from each object in the array, based on their address property
I would like to convert something like this:
[
{
amount: 10,
address: a01,
...other props...
},
{
amount: 20,
address: b02,
...other props...
},
{
amount: 5,
address: a01,
...other props...
},
...
]
to:
[
{
address: a01,
totalAmount: 15,
...other props...
},
{
address: b02,
totalAmount: someTotaledAmount,
...other props...
},
...
]
Should I be using reduce to consolidate the objects in the array?
Thank you!