0

So I have an empty array and and I am adding two arrays each with two elements using a for loop. So when I update my first element in the first array, my second array first element also gets updated. What is the issue ? Please help.

let matrix = []
let point = [0, 0]

for (let x = 0; x < 2; x++){
    matrix.push(point)
}

matrix[0][0] = 1

console.log(matrix)

0 Answers0