Build a NodeList. Three children: element, text, element.
Call values(). You get an iterator of those Node objects.
Loop with for...of. Each step yields the next node.
Print a readable form. Text nodes show #text; elements show a tag-like label.
Example 2 — Log Each nodeName
A short loop that prints the type name of every value.
JavaScript
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
node.appendChild(document.createTextNode("hey"));
node.appendChild(document.createElement("span"));
for (const value of node.childNodes.values()) {
console.log(value.nodeName);
}
Select elements.querySelectorAll returns a static NodeList of li nodes.
Call values(). Iterate the element nodes themselves.
Read text.textContent gives each list item’s label.
Same as default iteration.for (const value of items) would work the same way.
Compatibility
Browser Support
NodeList.values() is Baseline Widely available (MDN, since October 2017). It works across modern desktop and mobile browsers.
✓ Baseline · Widely available
NodeList.values()
Iterator of Node objects for for...of and Array.from.
WideModern browser support
Google ChromeSupported · modern versions
Full support
Mozilla FirefoxSupported · modern versions
Full support
Apple SafariSupported · modern Safari / iOS
Full support
Microsoft EdgeSupported · Chromium Edge
Full support
OperaFollow Chromium
Full support
Internet ExplorerNo NodeList.values()
Not supported
values()Widely available
Bottom line: Safe for modern web apps. Use for...of or Array.from to consume the iterator. Internet Explorer does not support NodeList iterator methods.
Frequently Asked Questions
An iterator of Node objects — the actual DOM nodes in the NodeList, in order. Each step yields a node, not an index number (MDN).
No. MDN marks NodeList.values() as Baseline Widely available (since October 2017). It is not Deprecated, Experimental, or Non-standard.