Following is my array -
const products = [{
id: "1",
quantity: 3
}, {
id: "2",
quantity: 3
}]
console.log(products.reduce((acc, product) => acc.quantity + product.quantity)) // 6 -> Correct
But if array contains more than 2 items it is throwing NaN
as a result, Let me know what I am doing wrong here.
const products = [{
id: "1",
quantity: 3
}, {
id: "2",
quantity: 3
}, {
id: "3",
quantity: 4
}]
console.log(products.reduce((acc, product) => acc.quantity + product.quantity)) // NaN -> InCorrect