I have an array:
const products = [
{ product: 'banana', price: 3 },
{ product: 'mango', price: 6 },
{ product: 'potato', price: ' ' },
{ product: 'avocado', price: 8 },
{ product: 'coffee', price: 10 },
{ product: 'tea', price: '' },
]
And Iwould like to sum all prices. What I tried:
const sum = products.reduce(function(acc, cur){
if (Number.isInteger(cur.price))
return acc+cur.price
}, 0)
console.log(sum)
it returns undefined. I also tried that without the condition, it returns a string. Where do I make a mistake?
productsin the second snippet. Also, the first snippet is unnecessary; just use a code block if your code doesn't have any output.elsealso