Skip to content

Instantly share code, notes, and snippets.

@alizhdanov
Created October 19, 2017 15:55
Show Gist options
  • Save alizhdanov/71b306ccda3c5bd87fdc999f3ee832af to your computer and use it in GitHub Desktop.
Save alizhdanov/71b306ccda3c5bd87fdc999f3ee832af to your computer and use it in GitHub Desktop.
Nodelist (HTMLCollection) to Array
// All credits and inspiration from this article https://hackernoon.com/htmlcollection-nodelist-and-array-of-objects-da42737181f9
const nodelist = document.querySelectorAll('.articles');
// Array.from method
// not supporting IE, Safari >= 9, probably will require pollyfill in your project
const array = Array.from(nodelist)
// Array.prototype.slice
// if i'm right browser support for this method even better than for HTMLColections, no pollyfils bro
const array = Array.prototype.slice.call(nodelist)
// Spread operator
// not supported by IE, but if you use babel, probably, you don't have anything to worry
const array = […nodelist]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment