I am trying to create a 6 by 12 matrix using Array.fill
let m = Array(6).fill(Array(12).fill(0));
While this works, the problem is that the internal arrays are actually referring to the same object Array.
let m = Array(6).fill(Array(12).fill(0));
m[0][0] = 1;
console.log(m[1][0]); // Outputs 1 instead of 0
I wanted (and expected) the meaning to m[1][0]be 0.
How can I make Array.fillcopies fill in by the values of this argument (for example: Array(12).fill(0)- this is an argument in my case) instead of copying by reference?
source
share