-5

So if you're answer is not then why we can use array foreach method with node list

And with html collection we can't use foreach method however html collection is also not an array

Thanks

  • "*then why we can use array foreach method with node list*" because you use the [NodeList `.forEach()`](https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach) not [the Array `.forEach()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach) – VLAZ Jul 02 '21 at 14:41
  • 1
    it's simple: a NodeList is a NodeList, a HTMLCollection is a HTMLCollection, and an Array is an Array -, but to add to the confusion: a HTMLCollection is always a live list of Nodes- a NodeList can either be a static or a live list of Nodes ... and an Array remains an Array and can contains Nodes or not – Jaromanda X Jul 02 '21 at 14:41
  • [What do querySelectorAll and getElementsBy* methods return?](https://stackoverflow.com/q/10693845) – VLAZ Jul 02 '21 at 14:44

1 Answers1

2

No, NodeList is not an array.

Any object may have a forEach method. NodeList is such an object: NodeList.prototype.forEach().

HtmlCollection does not implement forEach, so you cannot use forEach on it.

user229044
  • 232,980
  • 40
  • 330
  • 338