Skip to content

Instantly share code, notes, and snippets.

@devinsays
Created August 20, 2018 20:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devinsays/aee5aefc75e9de2f2d88f2c650ce0677 to your computer and use it in GitHub Desktop.
Save devinsays/aee5aefc75e9de2f2d88f2c650ce0677 to your computer and use it in GitHub Desktop.
How to Convert a NodeList to an Array

Let's say you're selecting a DOM element like list items.

Option #1, use a spread:

const items = [... document.querySelectorAll('li')];

Option #2, use Array.from:

const items = Array.from(document.querySelectorAll('li'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment