I have array of object that each object has (type and amount), I want to add the amounts of all objects that has same type.
for example, that's my array of object:
const arr = [
{
type: "A",
amount: 15
},
{
type: "A",
amount: 10
},
{
type: "B",
amount: 5
}
]
and that's the result I want:
const arr = [
{
type: "A",
amount: 25
},
{
type: "B",
amount: 5
}
]