You are working with a NodeList after querying the DOM and want to iterate over each node. Which loop would be directly usable without converting the NodeList to an array?

  • for...in loop
  • for...of loop
  • while loop
  • NodeList.prototype.forEach() method
The NodeList is not an array, but you can use the NodeList.prototype.forEach() method directly to iterate over its nodes without converting it to an array. It provides a convenient way to work with NodeLists, making it the suitable choice.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *