I have an array of obj where there are some numb and I want to find the sum. I know how to achieve this with a simple array but in this case it seems confusing.
I tried to use reduce as we do normally in an array but it didn't work.
const arr = [{ some: 1 }, { some: 2 }, { some: 3 }]
const sumArr = arr.reduce((a, b) => a.some + b.some, 0)
console.log(sumArr)
for example I know that I can do:
const arr = [1, 2, 3, 4, 5]
const sumArr = arr.reduce((a, b) => a + b, 0)
console.log(sumArr)
If I have an array like [{a: 1}, {a: 2}, {a: 3}, {b: 4}, {b: 5}]
I would like to find the sum
for all the a
and do the same for all the b
.