Push vs Assign vs Unshift

Edit on GitHub

Setup

var count = 100;
var arr = [];

Tests

  • Push

    for (var i = 1; i < count; i++) {
      arr.push(i);
    }
  • Assign

    arr.length = count;
    for (var i = 1; i < count; i++) {
      arr[i] = i;
    }
  • Unshift

    for (var i = 1; i < count; i++) {
      arr.unshift(i);
    }