The values() method of a NodeList returns an iterator of Node objects. Learn for...of over list.values(), how it compares to plain for...of list, keys(), and entries()—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Iterator
03
Yields
Nodes
04
Params
None
05
Loop
for...of
06
Status
Baseline widely
Fundamentals
Introduction
A NodeList holds an ordered collection of DOM nodes. list.values() lets you walk those nodes one by one through an iterator—each step gives you the next Node, not an index number.
MDN’s classic setup: three children in a div produce <p>, a text node "hey", and <span> when you log each value from childNodes.
💡
Beginner tip
You can often write for (const node of list) instead of for (const node of list.values())—they behave the same because NodeList is iterable.
Concept
Understanding the values() Method
An instance method on NodeList that returns an iterator over all values in the list. The values are Node objects (elements, text nodes, comments, etc.).
Returns — an iterator (not an array).
Each step — the next Node in order.
Parameters — none.
Does not mutate the NodeList or the DOM by itself.
Baseline Widely available on MDN (since October 2017).
Foundation
📝 Syntax
Call the method on a NodeList:
JavaScript
values()
Parameters
None.
Return value
An iterator. Each yielded value is a Node.
Typical pattern (MDN idea)
JavaScript
const list = node.childNodes;
for (const value of list.values()) {
console.log(value);
// <p>, #text "hey", <span>
}
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
node.appendChild(document.createTextNode("hey"));
node.appendChild(document.createElement("span"));
const list = node.childNodes;
for (const value of list.values()) {
console.log(value);
}
NodeList.values() is marked Baseline Widely available on MDN (since October 2017). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Baseline · Widely available
NodeList.values()
Returns an iterator of Node objects. Use for...of or Array.from to consume it.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNo NodeList.values() (use a polyfill or indexed for loop)
Unsupported
NodeList.values()Excellent
Bottom line: Call list.values() when you need nodes as an iterator—for...of list is often enough.
Wrap Up
Conclusion
NodeList.values() is the node iterator for a NodeList. Use for...of to walk each DOM node, or Array.from when you need a real array. For indexes only, use keys(); for both index and node, use entries().