I would like to push some element in a 2-D empty Array, and I find some problem with the push method.
var a = [[],[],[]];
a[1].push(1);
console.log(a);
//result: [ [], [ 1 ], [] ]
The above code will get the correct result, but the push method always push to all index if I use new Array method. Did I do something wrong with it?
var a = new Array(3).fill([]);
// a = [[], [], []]
a[1].push(1);
console.log(a);
//result: [ [ 1 ], [ 1 ], [ 1 ] ],
//but I think it should be [ [], [ 1 ], [] ] if I only push 1 to a[1]