I'm creating a 3x3 grid in JavaScript with all values initialized to false
like so:
let myGrid = Array(3).fill(Array(3).fill(false));
After initialization the grid values are:
[false, false, false],
[false, false, false],
[false, false, false]
If I then set the element [0,0] to true, like:
myGrid[0][0] = true;
I would expect the values to be:
[true, false, false],
[false, false, false],
[false, false, false]
But in fact, the resulting 2d array becomes:
[true, false, false],
[true, false, false],
[true, false, false]
Why has the first element in every inner array changed when I've only set the first element of the first array?