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) )
1.4m articles
1.4m replys
5 comments
57.0k users