I'm struggling with a weird Array.prototype.fill
behaviour:
const arr = new Array(5)
.fill([]);
arr[0].push('element pushed to 0 only');
console.log(arr[1]); // ['element pushed to 0 only']
All of the items inside the array are filled with this string. I assume all of the []
array-s are pointing to the same array, but I don't see why, could anyone explain?