<
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
>