title: How does a javascript array work whilst pushing new elements?
body: <p>I tested this code in Chrome / Firefox :</p>
  
  <pre><code>console.time('simple push');
  var arr0 = [];
  for(var i =0; i &lt; 1000000; i++){
      arr0.push(i);
  }
  console.timeEnd('simple push');
  console.time('set length and push');
  var arr1 = [];
  arr1.length=1000000;
  for(var j =0; j &lt; 1000000; j++){
      arr1[j]=j;
  }
  console.timeEnd('set length and push');
  console.time('new Array push');
  var arr2 = new Array(1000000);
  for(var k =0; k &lt; 1000000; k++){
      arr2[k]=k;
  }
  console.timeEnd('new Array push');
  </code></pre>
  
  <h1>Chrome 13 Result</h1>
  
  <p>simple push:59ms<br/>
  set length and push:192ms<br/>
  new Array push:187ms</p>
  
  <h1>Firefox 4 Result</h1>
  
  <p>simple push:76ms<br/>
  set length and push:44ms<br/>
  new Array push:40ms</p>
  
  <h1>My doubt</h1>
  
  <p>So <code>new Array</code> operation is definitely the slowest, but I wanna know why?<br/>
  Why set length behaves different in Chrome and Firefox, it seems preallocated memory doesn't works well in Chrome?</p>
  
  <h1>Update</h1>
  
  <p>I updated Chrome and FF results.</p>