let arr = [[1,2,3], [4,5,6], [7,8,9]]
arr[0][1] = 'X'
arr[1][1] = 'O'
console.log(arr);
I'm trying to work out a preliminary tic-tac-toe game and this method to create the table serves me fine.
Upon reading up on other methods to generate a matrix array table I found this
let newArr = new Array(3).fill(new Array(3))
newArr[0][1] = 'X'
console.log(newArr)
As I attempt to return newArr it actually replaces the entire column with 'X'.
Why is it doing that? I was thinking maybe during the stack it recognized I was naming the value of one undefined index and would just much rather do the same for the entire column but I cannot confirm.