title: Initialising an array of objects with the index as key
body: <p>I'm trying to find out how to initialise an array of objects, where each object has the index (i) as its key and 0 as its value. The code below is not working as expected but I can't see why. I'm still quite beginner with Javascript and couldn't find an answer elsewhere.</p>
  <pre><code>var n = 10;
  var sample = [];
  for (var i = 0; i &lt; n; i++)
      sample.push({i : 0});
  </code></pre>