NodeList.keys() returns an iterator of the list’s zero-based indexes (0, 1, 2, …). Use it with for...of when you need positions, not the nodes themselves (MDN).
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call nodeList.keys. Start with this line.
JavaScript
nodeList.keys()
Call
What it does
nodeList.keys()
Primary signature.
nodeList.keys(...)
Call with the arguments your case needs.
Built into the browser. Call keys(...) on a NodeList — no import required.
Library declarations
JavaScript
nodeList.keys()
Parameters
Parameter
Description
keys()
Required. Returns the index iterator
Return Value
Return Value
Description
*
Iterator of unsigned integers
JavaScript Examples
Example 1 — for...of over keys()
MDN pattern: log every index in a NodeList.
JavaScript
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 key of list.keys()) {
console.log(key);
}
Select nodes.querySelectorAll("button") returns a NodeList (demo page has two buttons).
Convert the iterator.Array.from(buttons.keys()) builds [0, 1, …].
Length matches. One key per node — same count as buttons.length.
Why arrays help. You can use array helpers (map, filter) on the indexes afterward.
Compatibility
Browser Support
NodeList.keys() is Baseline Widely available (MDN, since October 2017). It works across modern desktop and mobile browsers.
✓ Baseline · Widely available
NodeList.keys()
Iterator of zero-based NodeList indexes 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.keys()
Not supported
keys()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 unsigned integers — the zero-based indexes of the NodeList (0, 1, 2, …). Each step yields a number, not a Node (MDN).
No. MDN marks NodeList.keys() as Baseline Widely available (since October 2017). It is not Deprecated, Experimental, or Non-standard.