Skip to content

Instantly share code, notes, and snippets.

@garystorey
Created May 21, 2013 21:41
Show Gist options
  • Select an option

  • Save garystorey/5623492 to your computer and use it in GitHub Desktop.

Select an option

Save garystorey/5623492 to your computer and use it in GitHub Desktop.
Converts a nodelist returned by QSA to an array.
var nodelist =document.querySelectorAll("div")
/* THIS - easier to type*/
var nodesArray = [].slice.call( nodelist );
/* OR */
var nodesArray = Array.prototype.slice.call( nodelist )
/* OR THE FASTEST (for Chrome anyway) */
var l = nl.length, arr = new Array( l );
while( l-- ){ arr[l] = nl[l] };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment