js array of arrays code example

Example 1: how to read 2 dimensional array in javascript

activities.forEach((activity) => {
    activity.forEach((data) => {
        console.log(data);
    });
});

Example 2: javascript define multidimensional array

var iMax = 20;
var jMax = 10;
var f = new Array();

for (i=0;i<iMax;i++) {
 f[i]=new Array();
 for (j=0;j<jMax;j++) {
  f[i][j]=0;
 }
}

Example 3: multi dimensional array javascript

//2D array
let activities = [
    ['Work', 9],
    ['Eat', 1],
    ['Commute', 2],
    ['Play Game', 1],
    ['Sleep', 7]
];

Example 4: creating 2d array in javascript

var [r, c] = [5, 5]; 
var m = Array(r).fill().map(()=>Array(c).fill(0));

Example 5: array of in javascript

The Array. of() method creates a new Array instance from a variable number of 
arguments, regardless of number or type of the arguments. The difference between
Array. of() and the Array constructor is in the handling of integer arguments: Array.

Example 6: array of array

String[][] arrays = new String[][] { array1, array2, array3, array4, array5 };