I'm hoping to create an array and fill it with empty objects.
However, the method that I'm using is not working. It's my understanding the problem is that in Javascript, objects are passed by reference. Here's what I'm trying.
let myArray = Array(10).fill({});
When I try to set the value of an object in the array, it sets the value for all of the objects (because they're all referring to the same place in memory, I think). For example:
myArray[3]['text'] = 'Some text';
This returns the following array:
0: {text: "someText"}
1: {text: "someText"}
2: {text: "someText"}
3: {text: "someText"}
4: {text: "someText"}
5: {text: "someText"}
6: {text: "someText"}
7: {text: "someText"}
8: {text: "someText"}
9: {text: "someText"}
How can I create an empty array and fill it with unique objects, so that I can set property values individually? My desired output would be:
0: {}
1: {}
2: {text: "someText"}
3: {}
4: {}
5: {}
// And so on