function with 2 dimensional array javascript 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: javascript multidimensional array
var items = [
[1, 2],
[3, 4],
[5, 6]
];
console.log(items[0][0]);
console.log(items[0][1]);
console.log(items[1][0]);
console.log(items[1][1]);
console.log(items);