Javscript генерирует пустой 2D массив
var grid = [...Array(width)].map(e => Array(height));
// access via grid[y][x]
just-saved-you-a-stackoverflow-visit
var grid = [...Array(width)].map(e => Array(height));
// access via grid[y][x]