kiborgok
kiborgok

Reputation: 1

I should be getting [[1,0],[0,0]] why am I getting [[1,0],[1,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)

Upvotes: 0

Views: 19

Answers (0)

Related Questions