When I create an array of empty arrays with the following code:
const arrayOfArrays = new Array(3).fill([])
As expected, I get [[],[],[]
. However let's say I change the value with:
arrayOfArrays[0][0] = 'foo'
I expect to get [['foo'],[],[]]
but I end up with [['foo'],['foo'],['foo']]
. Why is this the case? How can I get it so that it works as expected?