Array.prototype.fill() with object passes reference and not new instance
<p>I was toying a bit and was trying to instantiate a new array of length <code>x</code>, where all elements of that array were initialized to a value <code>y</code>:</p>
<pre><code>var arr = new Array(x).fill(y);
</code></pre>
<p>This works well if the value of <code>y</code> is anything other than <strong>an object</strong>.
Meaning that if <code>y</code> is an object, the following is true:</p>
<pre><code>var arr = new Array(2).fill({});
arr[0] === arr[1]; //is true;
arr[0].test = 'string';
arr[1].test === 'string'; //is also true;
</code></pre>
<p>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?</p>