Confusion in reduce

In addition to the callback function, reduce has an additional parameter which takes an initial value for the accumulator. If this second parameter is not used, then the first iteration is skipped and the second iteration gets passed the first element of the array as the accumulator.
so, I did,

const users = [
  { name: 'John', age: 34 },
  { name: 'Amy', age: 20 },
  { name: 'camperCat', age: 10 }
];

const sumOfAges = users.reduce((sum, user) => sum + user.age, 0);
console.log(sumOfAges); // 64

in place of above I changed
const sumOfAges=users.reduce((sum,user)=>(sum+user.age));
it does’t work why ??

What is the first element of the array?

Oh thanks its object that’s why its not working
thanks.

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