Skip to content

Nodelist to array algorithm

CamiloMM edited this page Jun 16, 2013 · 2 revisions

I know what you're thinking - that the following code should do the trick:

//nl is a NodeList
var arr = Array.prototype.slice.call(nl);

But sorry, it doesn't work on IE8 (the reason is that NodeList is a host object on IE8 - and host objects can basically get away with anything. NodeList is not an Object!).

So we need something that does work on IE8!

Let's see.

After a bit of investigation, it looks like different algorithms may work best with different browsers:

JsPerf Screenshot

Which is kinda sad, but well, here's the benchmark. I'm not sure which to pick, right now.

There's some discussion on this StackOverflow question, too.