i have an array of objects that returns name: string and quantity: number, the thing is i have many objects into the array with the same name field value but different quantity values, so i want to show the total of all the quantities for each duplicated name. My code here:
const productsArray = [{ name: "lamp", quantity: 10 }, {name: "glass", quantity: 4}, {name:"lamp", quantity: 5}]
Lamp is repeated but it has different quantity values, so i want to merge those quantity values into one total quantity and show the name only once.
DESIRED RESULT
PRODUCT NAME: lamp PRODUCT QUANTITY: 15
PRODUCT NAME: glass PRODUCT QUANTITY: 4
Please help