So, I've initialized a multidimensional array like this.
let arr = new Array(5).fill(new Array(5).fill(0));
doing
arr[2][3] = 1;
Will give us
0 0 0 0 0
0 0 0 0 0
1 1 1 1 1
0 0 0 0 0
0 0 0 0 0
Why is this? I would guess it's a pass by reference issue and that's just a single array with references in each subsequent index, but I'm creating a new one, so why does this happen?
let arr = new Array(5).fill(new Array(5).fill(0));
arr[2][3] = 1;
console.log(JSON.stringify(arr));