Why does pushing to one array affect all the arrays in my two-dimensional array?
I was trying to initialize a simple two dimensional array as follows:
const arrays = Array(3).fill();
However, when I tried to push an entry into one of the arrays, it seems like it gets pushed to all of them for some reason:
arrays.push('foo'); console.log(arrays); // [ [ 'foo' ], [ 'foo' ], [ 'foo' ] ]
Why is this happening, and what can I do to fix it?