javascript - SUM of all elements of a two-dimensional array - Stack Overflow

PHOTO EMBED

Sat Dec 04 2021 19:54:36 GMT+0000 (UTC)

Saved by @tolanisirius #javascript

function sum(arr) {
  let sum = 0;
  for (let i = 0; i < arr.length; i++) {
    for (let j = 0; j < arr[i].length; j++) {
      sum += arr[i][j];
    }
  }
  return sum;
}
content_copyCOPY

https://stackoverflow.com/questions/62514193/sum-of-all-elements-of-a-two-dimensional-array