hello, i got a question like to know how can i solve this ?
let say this Cart array got a few objects
[ { id : 1, name: Nokia, price: 10, merchant_id : 1, quantity: 3 },
{ id : 2, name: Beer, price: 20, merchant_id : 1, quantity: 1 },
{ id : 3, name: Mercedes, price: 20, merchant_id : 2, quantity: 2 },
{ id : 4, name: Sushi, price: 60, merchant_id : 3, quantity: 35 },
{ id : 5, name: Iphone, price: 10, merchant_id : 4, quantity: 12 },
{ id : 6, name: Sushi, price: 70, merchant_id : 2, quantity: 5 },
]
example :
merchant id 1 got 2 items, and total quantity for this will be 4
merchant id 2 got 2 items, and total quantity for this will be 7
merchant id 3 got 1 items, and total quantity for this will be 35
merchant id 4 got 1 items, and total quantity for this will be 12
Can do i sum up the all the quantities based on merchant id and pushed to a new array with 4 objects of total quantity?
regards and thank you for your teaching