JavaScript NodeList entries() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Baseline Widely available
Instance method

What You’ll Learn

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

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.

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).

📝 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, 

], [1, #text "hey"], [2, ] }

⚡ Quick Reference

GoalCode / note
Get iteratorlist.entries()
Loop pairsfor (const entry of list.entries())
Destructurefor (const [i, node] of list.entries())
To arrayArray.from(list.entries()) or [...list.entries()]
ParametersNone
MDN statusBaseline Widely available (since October 2017)

🔍 At a Glance

Four facts to remember about NodeList.entries().

Returns
iterator

[i, Node]

Params
none

No arguments

Mutates?
no

Read-only walk

Baseline
widely

Since Oct 2017

Examples Gallery

Examples follow MDN NodeList.entries(). Labs use childNodes and querySelectorAll.

📚 Getting Started

Walk entries the MDN way.

Example 1 — for...of Over entries() (MDN Idea)

Build a small tree, then log each [index, node] pair from childNodes.

JavaScript
const node = document.createElement("div");
const kid1 = document.createElement("p");
const kid2 = document.createTextNode("hey");
const kid3 = document.createElement("span");
node.appendChild(kid1);
node.appendChild(kid2);
node.appendChild(kid3);

const list = node.childNodes;

for (const entry of list.entries()) {
  console.log(entry);
}
Try It Yourself

How It Works

MDN’s sample yields three pairs: a paragraph, a text node, and a span—indexes starting at 0.

Example 2 — Destructure [index, node]

Unpack the pair so you can use the index and node separately.

JavaScript
for (const [index, child] of list.entries()) {
  console.log(index, child.nodeName);
}
Try It Yourself

How It Works

Destructuring keeps the loop readable when you need both the position and the node.

📈 Selectors & Arrays

Use entries with querySelectorAll and Array.from.

Example 3 — querySelectorAll Entries

Static NodeLists from selectors also support entries().

JavaScript
const items = document.querySelectorAll("li");

for (const [i, el] of items.entries()) {
  console.log(i, el.textContent);
}
Try It Yourself

How It Works

Great for numbering list items or applying index-based styles without a manual counter.

Example 4 — Materialize With Array.from

Turn the iterator into a real array of pairs.

JavaScript
const pairs = Array.from(list.entries());
console.log(pairs.length);
console.log(pairs[0][0], pairs[0][1].nodeName);
Try It Yourself

How It Works

Use this when you need array methods (map, filter) on the pairs.

Example 5 — entries() vs forEach()

Both can expose an index; entries() is the iterator style.

JavaScript
// Iterator style
for (const [i, n] of list.entries()) {
  console.log("entries", i, n.nodeName);
}

// Callback style
list.forEach((n, i) => {
  console.log("forEach", i, n.nodeName);
});
Try It Yourself

How It Works

Pick forEach for simple callbacks; pick entries() when you want for...of, early break, or array conversion.

🚀 Common Use Cases

  • Number children while walking childNodes.
  • Label querySelectorAll matches with their index.
  • Build debug logs of [index, nodeName] pairs.
  • Convert pairs with Array.from for further processing.
  • Teach iterators alongside Array entries().

🔧 How It Works

1

Get a NodeList

From childNodes, querySelectorAll, or another DOM API that returns a NodeList.

DOM
2

Call entries()

list.entries() returns a fresh iterator over [index, node] pairs.

Call
3

Iterate

for...of (or Array.from) pulls each pair until the list is exhausted.

Loop
4

Use the pair

Log, style by index, or process the Node without mutating the list.

📝 Notes

  • MDN: Baseline Widely available (since October 2017) — no Deprecated / Experimental / Non-standard banner.
  • Returns an iterator; values are Node objects.
  • childNodes includes text nodes—expect #text entries when whitespace or text is present.
  • Does not mutate the DOM by itself.
  • Related learning: childNodes, Array.entries(), appendChild(), JavaScript hub.

Universal Browser Support

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.

Universal Widely available
Google Chrome Full support · Desktop & Mobile
Full support
Mozilla Firefox Full support · Desktop & Mobile
Full support
Apple Safari Full support · macOS & iOS
Full support
Microsoft Edge Full support · Chromium
Full support
Opera Full support · Modern versions
Full support
Internet Explorer No 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.

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.

Continue with forEach(), childNodes, Array.entries(), or the JavaScript hub.

💡 Best Practices

✅ Do

  • Use entries() when you need both index and node
  • Destructure with [i, node] for clarity
  • Remember childNodes includes text nodes
  • 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)

Key Takeaways

Knowledge Unlocked

Five things to remember about NodeList.entries()

Index + Node pairs, as an iterator.

5
Core concepts
⚙️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.

Next: NodeList.forEach()

Learn how to run a callback for every node.

forEach() method →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful