Tuesday, 15 July 2014

Is there a reason JavaScript developers don't use Array.push()? -


I generally use expressions like JavaScript in the following:

  Arr = [] Arr [arr.length] = "something" arr [arr.length] = "one more thing"   

whether push will not be more suitable ?

  arr = [] arr.push ("some") arr.push ("one other thing")    

I actually asked the same question at the beginning of this year renewed with new test cases

It is that the push in Chrome is very high, and is equal to FF. Also can be faster in IE 9, but I would be interested to see how it works in IE 10.

I would say that most developers would agree to set the length of Array, and then it would be faster to use straightforward work, as is the case with most programming languages, but javascript is different. , They are just key / value maps like all other Javascript objects. Therefore, prior allocation is essentially falling on deaf ears.

Personally, I push (:

No comments:

Post a Comment