I don't know why I'm seeing the below:
const sideLength = 4;
const multiArray = new Array(sideLength).fill(new Array(sideLength));
console.log(multiArray)
var counter = 1;
multiArray[3][1] = counter;
console.log('multiArray:', multiArray)
Console output:
[ [ , , , ], [ , , , ], [ , , , ], [ , , , ] ]
multiArray: [ [ , 1, , ], [ , 1, , ], [ , 1, , ], [ , 1, , ] ]
I would have expected the second line of output to be:
multiArray: [ [ , , , ], [ , , , ], [ , , , ], [ , 1, , ] ]
Why is that 1 being added to every array's index=1 element?