How to Utilise the Reduce Method on an Array of Objects?
const fruits = [
{ name: 'Apple', quantity: 20 },
{ name: 'Banana', quantity: 35 },
{ name: 'Orange', quantity: 50 },
{ name: 'Grapes', quantity: 15 }
];
const totalQuantity = fruits.reduce((accumulator, fruit) => {
return accumulator + fruit.quantity;
}, 0);
console.log("Total fruit quantity:", totalQuantity); // 120