Why is Array.prototype.push faster than variable declaration

92 Views Asked by At

I ran the following jsperf https://jsperf.com/push-vs-define-anaoum

and found out that push in this case :

var a = [];
a.push([1,2,3]);
a.push(["a","b","c"]);

is faster than just declaring a with the subarrays inside :

var a = [
  [1,2,3],
  ["a","b","c"]
];

Could anyone please tell me why or point me in the right documentation?

Thanks enter image description here

1

There are 1 best solutions below

1
Mr Phoenix On

For me declaring a with sub arrays went faster than push :)

I think it depends on computer's/device's components

My example