Created
October 19, 2017 15:55
-
-
Save alizhdanov/71b306ccda3c5bd87fdc999f3ee832af to your computer and use it in GitHub Desktop.
Nodelist (HTMLCollection) to Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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