I'm trying to create two dimensional array using fill
functions. It's looks like this:
let map = new Array(3)
.fill(new Array(3)
.fill(0));
Problem appears when I try to set one value at specific index:
map[1][1] = 1;
I expect to have result:
[[0, 0, 0],[0, 1, 0],[0, 0, 0]]
But I receive this:
[[0, 1, 0],[0, 1, 0],[0, 1, 0]]
It looks like all this subarrays referencing to one array but why?