0

I have the below array

[
   {item_id:1,quantity:5},
   {item_id:1,quantity:10},
   {item_id:2,quantity:45},
   {item_id:2,quantity:30},
   {item_id:2,quantity:20}
   {item_id:3,quantity:10},
]

Now i want to get the sum of each item_id so the result will be the below array

[
   {item_id:1,quantity:15},
   {item_id:2,quantity:95},
   {item_id:3,quantity:10},
]

Could you please help me with this.

Thanks.

2
  • 1
    What have you tried so far? Have you looked into how the .map() or .reduce() function works for Arrays in JavaScript? Commented Mar 21, 2018 at 23:53
  • 1
    w3schools.com/code/tryit.asp?filename=FPLBGFR3QDXI Commented Mar 22, 2018 at 1:02

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.