I'm fairly new to using .reduce() and am wondering what the best to find the sum of all of the numbers inside myArr would be.
const myArr = [ [ 10, 0 ], [ 10, 0 ], [ 2, 4 ], [ 2, 4 ] ]
You could flatten the array and then sum
flat
const myArr = [ [10, 0], [10, 0], [2, 4], [2, 4] ] console.log( myArr.flat().reduce((acc, curr) => acc + curr, 0) )
2.1m questions
2.1m answers
60 comments
57.0k users