js empty 2d array code example
Example 1: javscript generate empty 2d array
var grid = [...Array(width)].map(e => Array(height));
// access via grid[y][x]
Example 2: javascriopt initialize 2d array with size
function makeArray(w, h, val) {
var arr = [];
for(let i = 0; i < h; i++) {
arr[i] = [];
for(let j = 0; j < w; j++) {
arr[i][j] = val;
}
}
return arr;
}