I'm creating an array and populating it using the fill method but changing array1[0].foo changes all objects in the array.
const array1 = Array(2).fill({ foo: null })
array1[0].foo = 'bar' // [ { foo: 'bar' }, { foo: 'bar' } ]
Is there a way to use fill with different copies of the same object for every index?