make 2d array in js code example
Example 1: how to make a 2d array in js
let x = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
console.log(items[0][0]); // 1
console.log(items[0][1]); // 2
console.log(items[1][0]); // 4
console.log(items[1][1]); // 5
console.log(items);
Example 2: creating 2d array in javascript
var [r, c] = [5, 5];
var m = Array(r).fill().map(()=>Array(c).fill(0));