While NodeList and HTMLCollection share
similarities with arrays, there are important differences:
- Prototype Chain: They do not inherit from Array.prototype, so array methods are not directly available.
- Mutation Behavior: NodeList and HTMLCollection may be live, meaning they are automatically updated as the DOM changes.
- Accessing Elements: Elements in NodeList and HTMLCollection can be accessed by index like arrays but lack many array methods.
To utilize array methods like forEach, map,
and
filter, you need to convert NodeList and HTMLCollection into arrays.