Given a 3x3 matrix I want to set the element in the first row, 3rd column to true
.
I would expect that m[0][2] = true
would do it, but it does not. It sets the whole column to true!
My code to create the array and set the value is below. What caused this behavior?
const size = 3;
const m = Array(size).fill(Array(size).fill(false))
console.log(m);
/* [[false, false, false],
[false, false, false],
[false, false, false]]
*/
m[0][2] = true;
console.log(m);
/*
[[false, false, true],
[false, false, true],
[false, false, true]]
*/