I have a 2d array:
let arr = [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
When I try to update the 1st sub array in the 2nd position with:
arr[0][1] = 4
The output is:
[ [ 0, 4, 0, 0 ], [ 0, 4, 0, 0 ], [ 0, 4, 0, 0 ], [ 0, 4, 0, 0 ] ]
Why are all of the sub arrays updating?
The full code is:
let arr = [ [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ], [ 0, 0, 0, 0 ] ]
arr[0][1] = 4
console.log(arr)