The DOM method document.querySelectorAll()
(and a few others) return a NodeList
.
To operate on the list, e.g. using forEach()
, the NodeList
must first be converted to an Array
.
What's the best way to convert the NodeList
to an Array
?
With ES6 you can simply do:
const spanList = [...document.querySelectorAll("span")];