tow dimensional array in js code example
Example 1: js array two dimensional
const matrix = new Array(5).fill(0).map(() => new Array(4).fill(0));
console.log(matrix[0][0]);
Example 2: javascript two dimensional array
var grid = [];
iMax = 3;
jMax = 2;
count = 0;
for (let i = 0; i < iMax; i++) {
grid[i] = [];
for (let j = 0; j < jMax; j++) {
grid[i][j] = count;
count++;
}
}
console.log(grid[0][2]);
Example 3: multi dimensional array javascript
let activities = [
['Work', 9],
['Eat', 1],
['Commute', 2],
['Play Game', 1],
['Sleep', 7]
];