6

I got [object Object]9778177 as result, I tried to parse the value but doesn't help neither, something is wrong.

let x = [{
  "total_count": 7
}, {
  "total_count": 9
}, {
  "total_count": 778
}, {
  "total_count": 177
}]

let sum = x.reduce((accum, obj) => {
   return accum + obj.total_count
})

console.log(sum)
0

1 Answer 1

9

You could add a start value, because the first iteration starts with the object for the accumulator and there you have not the property, you would need.

let sum = x.reduce((accum, obj) => accum + obj.total_count, 0);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.