Consider the code below. I want to change only the second elements value in the second list in matrix
. The problem is, that somehow all elements are changed. How can this be?
let matrix = Array(2).fill(Array(2).fill(0));
// [[0, 0], [0, 0]]
matrix[1][1] = 8
console.log(matrix)
// [[0, 8], [0, 8]]