Categories
JavaScript Answers

How to convert a DOM node list to an array in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *