Using the push method or .length when adding to array?
I've generally thought length assignment was faster. Just found Index vs. push performance which backs that up; for my Chrome 14 browser anyway, over a single test run. However there is not much in it in Chrome.
Since arrays in JavaScript do not have holes the functionality of those two methods is equal. And yes, using .push()
is much cleaner (and shorter).
push is way faster, almost 300% faster.
Proof: http://jsperf.com/push-vs-length-test