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 can use the spread operator or the Array.from
method.
For instance, we write
const elements = [...nodeList];
or
const elements = Array.from(nodeList);
to use the spread operator or the Array.from
method to convert the nodeList
node list to an array.
Conclusion
To convert a DOM node list to an array in JavaScript, we can use the spread operator or the Array.from
method.