Categories
JavaScript Answers

How to convert a NodeList to an array with JavaScript?

Spread the love

To convert a NodeList to an array with JavaScript, we use the spread operator.

For instance, we write

const spanList = [...document.querySelectorAll("span")];

to select all spans and put them in a node list with querySelectorAll.

And then we spread the node list entries into an array with the spread operator.

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 *