Sometimes, we want to convert a DOM node list to an array in JavaScript.
In this article, we’ll look at how to convert a DOM node list to an array in JavaScript.
How to convert a DOM node list to an array in JavaScript?
To convert a DOM node list to an array in JavaScript, we use the spread operator.
For instance, we write
const elements = [...nodelist];
to spread the nodeList
entries into an array with the spread operator.
Conclusion
To convert a DOM node list to an array in JavaScript, we use the spread operator.