I am facing very weird problem here with Array constructor
in JavaScript. I declare an array with length 5 which further contains arrays. When I want to push an element in the first sub-array, it adds that element in all sub-arrays.
var items = new Array(5).fill([]);
items[0].push(1);
console.log(items.toString());
It gives 1,1,1,1,1
, but I am expecting 1,,,,
. Am I missing something here?