How to convert a HTML NodeList to an array in JavaScript

1 Answer

0 votes
<div>div 1 text</div>
<div>div 2 text</div>
<div>div 3 text</div>
<div>div 4 text</div>
<div>div 5 text</div>
const divs =  document.querySelectorAll('div');

const arr = [...divs];

for (let i = 0; i < arr.length; i++)
		console.log(arr[i].textContent); 


  
    
    
/*
run:
    
"div 1 text"
"div 2 text"
"div 3 text"
"div 4 text"
"div 5 text"
    
*/

 



answered Jun 15, 2021 by avibootz

Related questions

1 answer 305 views
1 answer 235 views
1 answer 322 views
1 answer 223 views
1 answer 225 views
1 answer 189 views
...