Notes on Day 18 of 30 Days of JavaScript

Table of Contents

Lessons Learned

NodeList

NodeList objects are collections of nodes, usually returned by properties such as Node.childNodes and methods such as document.querySelectorAll().

These are not of the array type and can be worked with common array methods by transforming them first into one:

const menuItems = document.querySelectorAll('ul.menu-items li')
NodeList.prototype.isPrototypeOf(menuItems)
> true

[...menuItems]
> [li, li, li, ...]

Array.from(menuItems)
> [li, li, li, ...]

References

Twitter, LinkedIn