DOM: Difference Between NodeList, HTMLCollection

By Xah Lee. Date: .

Has ForEach Method or is it Iterable?

HTMLCollection vs NodeList, on Google Chrome, Safari, Firefox, as of 2019-05-30
Interfacetrue arrayhas forEachiterable
HTMLCollectionnonoyes
NodeList noyesyes
// print info of a object, see if they are true array, or iterable.
// version 2022-08-20

const f_print_object_loop_support = ((x) => {
  console.log("Type is:", Reflect.apply(Object.prototype.toString, x, []));
  console.log("is true array:", Array.isArray(x));
  console.log("has forEach:", Reflect.has(x, "forEach"));
  console.log("is iterable:", Reflect.has(x, Symbol.iterator));
});

f_print_object_loop_support(document.getElementsByTagName("x"))
f_print_object_loop_support(document.getElementsByClassName("x"));
f_print_object_loop_support(document.getElementsByName("x"));
HTMLCollection vs NodeList 2022-08-20
HTMLCollection vs NodeList 2022-08-20

JavaScript/DOM: Node Name, Node Type, Node Value

BUY
Ξ£JS
JavaScript in Depth

DOM Scripting

Overview

DOM Methods

Basic Examples

HTML Input

Web Scripting Examples

Web Scripting Misc