Just a small question.
I was toying a bit and was trying to instantiate a new array of lenght x, where all elements of that array where initialized to a value y
var arr = new Array(x).fill(y);
This works well if the value of y is anything other than an object. Meaning that is y is an object, the following is true:
var arr = new Array(2).fill({});
arr[0] === arr[1]; //is true;
arr[0].test = 'string';
arr[1].test === 'string'; //is also true;
Is there any way to state that a new object should be created for each element while using the fill-function? Or should I just convert it to a loop?
Thanks in advance!