Previously answered questions here said that this was the fastest way:
//nl is a NodeList
var arr = Array.prototype.slice.call(nl);
In benchmarking on my browser I have found that it is more than 3 times slower than this:
var arr = [];
for(var i = 0, n; n = nl[i]; ++i) arr.push(n);
They both produce the same output, but I find it hard to believe that my second version is the fastest possible way, especially since people have said otherwise here.
Is this a quirk in my browser (Chromium 6)? Or is there a faster way?
arr[arr.length] = nl[i];
may be faster thanarr.push(nl[i]);
since it avoids a function call. – Wortmanvar i = nl.length, arr = new Array(i); for(; i--; arr[i] = nl[i]);
– Deist