The entries() method of a NodeList returns an iterator of key/value pairs. Each pair is [index, node], where the value is a Node. Learn for...of, destructuring, childNodes and querySelectorAll demos, and how it compares with keys(), values(), and forEach()—with five examples and try-it labs.
01
Kind
Instance method
02
Returns
Iterator
03
Params
None
04
Pair
[i, Node]
05
Loop
for...of
06
Status
Baseline widely
Fundamentals
Introduction
A NodeList is a collection of DOM nodes—for example element.childNodes or the result of document.querySelectorAll("li"). Sometimes you need both the index and the node while looping.
list.entries() gives you that: an iterator of [index, node] pairs, similar in spirit to Array.entries().
💡
Beginner tip
Prefer for (const [i, node] of list.entries()) when you need the index. If you only need the node, for...of list or list.values() is simpler.
Concept
Understanding the entries() Method
An instance method on NodeList that returns an iterator over all key/value pairs in the list. The values are Node objects.
Returns — an iterator (not an array).
Each step — [index, node].
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
entries()
Parameters
None.
Return value
An iterator. Each yielded value is a two-item array: [index, node].
Typical pattern (MDN idea)
JavaScript
const list = node.childNodes;
for (const entry of list.entries()) {
console.log(entry);
// e.g. [0,
NodeList.entries() 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.entries()
Returns an iterator of [index, Node] pairs. 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.entries() (use a polyfill or indexed for loop)
Unsupported
NodeList.entries()Excellent
Bottom line: Call list.entries() on childNodes or querySelectorAll results when you need both index and node.
Wrap Up
Conclusion
NodeList.entries() is the iterator for [index, node] pairs. Use it with for...of when you need the index, and fall back to forEach or plain for...of when you only need the node.
Use Array.from(list.entries()) when you need array methods
Prefer querySelectorAll when you only want element matches
❌ Don’t
Expect an array return value (it is an iterator)
Pass arguments to entries()
Assume every entry is an Element (text nodes appear too)
Mutate the list heavily while iterating live NodeLists without care
Reach for entries() when you only need nodes (use values() / for...of)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about NodeList.entries()
Index + Node pairs, as an iterator.
5
Core concepts
🔗01
Returns
iterator
API
⚙️02
Pair
[i, Node]
Shape
🔒03
No params
entries()
Rule
📄04
for...of
best friend
Loop
🎯05
Baseline
since Oct 2017
Status
❓ Frequently Asked Questions
An iterator of key/value pairs. Each step yields [index, node], where index is a number and node is a Node (Element, Text, etc.).
No. MDN marks NodeList.entries() as Baseline Widely available (since October 2017). It is not Deprecated, Experimental, or Non-standard.
Modern NodeLists do—including node.childNodes and the static list from document.querySelectorAll(...).
forEach() runs a callback for each node immediately. entries() returns a lazy iterator you loop with for...of, or turn into an array with Array.from / spread.
Same idea—[index, value] pairs—but NodeList.entries() walks DOM nodes in a NodeList, not array elements.
No. It only iterates existing nodes. It does not add, remove, or mutate nodes by itself.
Did you know?
MDN’s example logs each entry as a two-item array like [0, <p>]. Destructuring for (const [i, node] of list.entries()) is just a cleaner way to read those same pairs.