I want to create a certain number of objects in an array by using new Array().
This works, but as soon as I update one object inside the array, it updates every other object too.
const ar = Array(5).fill({})
console.log(ar)
// will log [{}, {}, {}, {}, {}]
ar[0].hello = 'hi'
console.log(ar)
// will log [{ hello: 'hi' }, { hello: 'hi' }, { hello: 'hi' }, { hello: 'hi' }, { hello: 'hi' }]
The expected result is this:
[{ hello: 'hi' }, {}, {}, {}, {}]