Why does document.querySelectorAll return a StaticNodeList rather than a real Array? Why does document.querySelectorAll return a StaticNodeList rather than a real Array? javascript javascript

Why does document.querySelectorAll return a StaticNodeList rather than a real Array?


You can use ES2015 (ES6) spread operator:

[...document.querySelectorAll('div')]

will convert StaticNodeList to Array of items.

Here is an example on how to use it.

[...document.querySelectorAll('div')].map(x => console.log(x.innerHTML))
<div>Text 1</div><div>Text 2</div>