Because .push () is a function call and the other is a direct assignment. Direct assignment is always faster.
Remember that in javascript, arrays are objects like everyone else. This means that you can assign properties to them.
In the special case of arrays, they have a built-in length property that gets an update behind the scenes (and many other optimizations under the hood, but that doesn't matter right now).
In a normal object, you can do this, but it is not an array:
var x = { 0: 'a', 1: 'b', 2: 'c' };
However, since arrays and hashes are both objects, this is equivalent.
var x = [ 'a', 'b', 'c' ];
Since x is an array in the second case, the length is automatically calculated and available.
source share