One data grid for JavaScript, React, Vue & Angular. Sorting, filtering, virtualization, pinning, and CSV export included. Early access $199 $349 → [Get it now]

How to convert NodeList to an array in JavaScript

When working with DOM manipulation, you often get a NodeList from methods like querySelectorAll(), but NodeLists lack many useful array methods. As the creator of CoreUI, a widely used open-source UI library, I’ve encountered this scenario countless times when building interactive components. I can tell you the most efficient and modern solution is to use the spread operator or Array.from(). Both methods are clean, readable, and supported in all modern browsers.

Convert a NodeList to an array using the spread operator [...] or Array.from().

const nodes = [...document.querySelectorAll('.item')]

or

const nodes = Array.from(document.querySelectorAll('.item'))

The spread operator ... takes all elements from the NodeList and expands them into a new array. Similarly, Array.from() creates a new array instance from any iterable object like a NodeList. Both approaches give you access to all array methods like map(), filter(), and reduce(), making DOM manipulation much more flexible and powerful.

Best Practice Note

This is the same approach we use in CoreUI components to ensure DOM queries can be easily transformed and manipulated. The spread operator is slightly more concise, but Array.from() can be more readable when you need to transform elements immediately using its optional mapping function.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.
How to get the last element in an array in JavaScript
How to get the last element in an array in JavaScript

How to compare dates with JavaScript
How to compare dates with JavaScript

How to disable a button in JavaScript
How to disable a button in JavaScript

How to check if a key exists in JavaScript object?
How to check if a key exists in JavaScript object?