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)
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With