NodeList is a collection of nodes. Node is any HTML or XML nodes, and also text content of a node, such as inner text of <b>β¦</b>. [see What is Node, Node Type, Element]
HTMLCollection is a collection of HTML/XML elements that are represented by tags. (exclude Whitespace Nodes or text nodes or comment nodes.)
Has ForEach Method or is it Iterable?
HTMLCollection vs NodeList, on Google Chrome, Safari, Firefox, as of 2019-05-30
Interface
true array
has forEach
iterable
HTMLCollection
no
no
yes
NodeList
no
yes
yes
// print info of a object, see if they are true array, or iterable.
// version 2022-08-20
constf_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"));