Iterating over multidimensional arrays in JavaScript

Let the following two-dimensional array be given:

let arr = [[1, 2, 3, 4, 5], [6, 7, 8], [9, 10]];

Let's output all its elements to the console. To do this, we need to run two nested loops:

let arr = [[1, 2, 3, 4, 5], [6, 7, 8], [9, 10]]; for (let subArr of arr) { for (let elem of subArr) { console.log(elem); } }

Given a 2D array of numbers:

let arr = [[1, 2, 3], [4, 5], [6]];

Use nested loops to find the sum of this array elements.

Given a 3D array of numbers:

let arr = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];

Use nested loops to find the sum of this array elements.

enru