0

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     
  } 
]
flacko
  • 125
  • 2
  • 9
  • @Ivar ironic how a duplicate can duplicate a duplicate :-P – malarres Apr 05 '22 at 07:02
  • 1
    @malarres True. :-) But sometimes those duplicates are better targets than the "original". Plus this way you have the chance to see all answers of both questions whereas if we would have marked the other one as duplicate target, there wouldn't be a link to the the current dupe target. – Ivar Apr 05 '22 at 07:57

0 Answers0