How to convert a DOM nodelist to an array using JavaScript ? Last Updated : 08 Feb, 2023 Comments Improve Suggest changes Like Article Like Report NodeList objects are the collection of nodes, usually returned by properties such as Node.childNodes and methods such as document.querySelectorAll(). Although NodeList is not an actual Array but it is possible to iterate over it with the help of forEach() method. NodeList can also be converted into actual array by following methods. Method 1: By using Array.prototype.slice.call() method. Syntax: const array = Array.prototype.slice.call(nodeList); // Normal Method const array = [].slice.call(nodeList); // Condensed Method Example: HTML <body> <p>Hello geeks 1</p> <p>Hello geeks 2</p> <p>Hello geeks 3</p> <p>Hello geeks 4</p> <script> // This is nodeList const nodeList = document.querySelectorAll('p'); console.log(nodeList); // Converting using Array.prototype.slice.call const array1 = Array.prototype.slice.call(nodeList); console.log(array1); </script> </body> Output: Method 2: With the help of Array.from() method. Syntax: const array = Array.from(nodeList); Example: HTML <body> <p>Hello geeks 1</p> <p>Hello geeks 2</p> <p>Hello geeks 3</p> <p>Hello geeks 4</p> <script> // This is nodeList const nodeList = document.querySelectorAll('p'); console.log(nodeList); // Converting to array using Array.from() method const array = Array.from(nodeList); console.log(array); </script> </body> Output: Method 3: Using ES6 spread syntax, it allows an iterable such as an array expression or string to be expanded in places where zero or more arguments or elements are expected. Syntax: const array = [ ...nodeList ] Example: HTML <body> <p>Hello geeks 1</p> <p>Hello geeks 2</p> <p>Hello geeks 3</p> <p>Hello geeks 4</p> <script> // This is nodeList const nodeList = document.querySelectorAll('p'); console.log(nodeList); // Converting using Spread syntax const array1 = [...nodeList]; console.log(array1); </script> </body> Output: Note: Method 2 and Method 3 may not work in older browsers properly but will work fine in all modern browsers. Comment More infoAdvertise with us Next Article How to convert a DOM nodelist to an array using JavaScript ? sanjeev2552 Follow Improve Article Tags : JavaScript Web Technologies HTML Write From Home JavaScript-Questions +1 More Similar Reads How to convert Integer array to String array using JavaScript ? The task is to convert an integer array to a string array in JavaScript. Here are a few of the most used techniques discussed with the help of JavaScript. Approaches to convert Integer array to String array:Table of ContentApproach 1: using JavaScript array.map() and toString() methodsApproach 2: Us 2 min read How to Create an HTML Table from an Object Array Using JavaScript ? Tables are a fundamental part of web development, and displaying data in a structured manner is a common requirement. JavaScript provides a powerful way to dynamically generate HTML content, making it easy to create tables from object arrays. Table of Content Using innerHTML propertyUsing appendChil 2 min read Fastest way to convert JavaScript NodeList to Array There are many ways to convert a NodeList to a JavaScript array but the fastest of all is a new method from ES6. In ES6, we can now simply create an Array from a NodeList using the Array.from() method. ApproachThe JavaScript Array.from() method is used to create a new array instance from a given arr 2 min read How to Convert Object to Array in JavaScript? In this article, we will learn how to convert an Object to an Array in JavaScript. Given an object, the task is to convert an object to an Array in JavaScript. Objects and Arrays are two fundamental data structures. Sometimes, it's necessary to convert an object to an array for various reasons, such 4 min read JavaScript - Convert an Array to an Object Here are some common methods which can be used to convert an array to an object: 1. Using JavaScript Object.assign() method The first approach is using the Object.assign() method. This method copies the values of all enumerable properties from source objects(one or more) to a target object.JavaScrip 3 min read Like