Why does my function return NaN?

Hello, I have a simple reduce method on my array but for some reason, it just returns NaN instead of calculating the values of each element.
Here’s the code:



let ab = [{
  value: 1111111111,
},{
  value: 100000,
},{
  value: 35453454545,
}]

console.log(ab.reduce((a,b)=>a.value+b.value))

Turns out I had to add the initial value so the function should look like this
(ab.reduce((a,b)=>a+b.value,0)

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.