Convert querySelectorAll NodeList to Array

January 03, 2019

There are multiple ways to make a NodeList iterable:

Most browser-compatible method:

const nodeList = document.querySelectorAll('.button')
const buttonsArray = Array.prototype.slice.call(nodeList)

Array.from alternative (not compatible with IE):

const nodeList = document.querySelectorAll('.button')
const buttonsArray = Array.from(nodeList)

ES6 Method:

const buttonsArray = […document.querySelectorAll('.button')]