Fastest way to convert JavaScript NodeList to Array Last Updated : 09 Jan, 2024 Comments Improve Suggest changes Like Article Like Report 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 array. In the case of a string, every alphabet of the string is converted to an element of the new array instance, and in the case of integer values, a new array instance simply takes the elements of the given array. Syntax:let my_arr = Array.from( given_nodelist );Example: This example shows the use of the above-explained approach. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <h1 style="color: green"> GeeksforGeeks </h1> <div class="content primary"> <p> A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and placement guides. </p> </div> <div class="content secondary"> <p>This example demonstrates the fastest way to convert from a NodeList to an array. </p> </div> <script> // This will act select all div DOM elements in the page let nodelist = document.querySelectorAll('div'); // This will convert the DOM NodeList // to a JavaScript Array Object let my_arr = Array.from(nodelist); // Display the array in the console console.log(my_arr); // Display all the values of the // array in the console for (let val of my_arr) { console.log(val); } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article Fastest way to convert JavaScript NodeList to Array N nakulgupta112233 Follow Improve Article Tags : JavaScript Web Technologies HTML JavaScript-Questions Similar Reads How to convert a DOM nodelist to an array using JavaScript ? 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 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 Convert an Array to JSON in JavaScript Given a JavaScript Array and the task is to convert an array to JSON Object. Below are the approaches to convert an array to JSON using JsvaScript: Table of ContentJSON.stringify() methodObject.assign() methodJSON.stringify() methodThe use of JSON is to exchange data to/from a web server. While send 2 min read Convert Array to String in JavaScript In JavaScript, converting an array to a string involves combining its elements into a single text output, often separated by a specified delimiter. This is useful for displaying array contents in a readable format or when storing data as a single string. The process can be customized to use differen 7 min read Fastest way to duplicate an array in JavaScript Multiple methods can be used to duplicate an array in JavaScript.The fastest way to duplicate an array in JavaScript is by using the slice() Method. Let us discuss some methods and then compare the speed of execution. The methods to copy an array are: Table of Content Using slice() Using concat() me 4 min read Like