JavaScript NodeList entries() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Method

Definition

NodeList.entries() returns an iterator of [index, node] pairs (MDN). Loop with for...of to walk every key/value pair in the list.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call nodeList.entries. Start with this line.

JavaScript
nodeList.entries()
CallWhat it does
nodeList.entries()Primary signature.
nodeList.entries(...)Call with the arguments your case needs.

Built into the browser. Call entries(...) on a NodeList — no import required.

Library declarations
JavaScript
nodeList.entries()

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*Iterator of [index, Node]

JavaScript Examples

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

MDN pattern: walk childNodes.entries() and read each pair.

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

const lines = [];
for (const entry of node.childNodes.entries()) {
  const index = entry[0];
  const child = entry[1];
  lines.push(index + " " + child.nodeName);
}
console.log(lines.join(", ")); // 0 P, 1 #text, 2 SPAN
Try It Yourself

How It Works

  1. Create a parent. Append three child nodes.
  2. Call entries(). No parameters.
  3. Read the pair. entry[0] is the index; entry[1] is the node.
  4. Print nodeName. Text nodes show as #text.

Example 2 — Destructuring

Unpack [index, node] in the for...of header.

JavaScript
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
node.appendChild(document.createElement("span"));

const lines = [];
for (const [index, child] of node.childNodes.entries()) {
  lines.push(index + "→" + child.nodeName);
}
console.log(lines.join(" | ")); // 0→P | 1→SPAN
Try It Yourself

How It Works

  1. Same iterator. Still list.entries().
  2. Destructure each step. Cleaner than entry[0] / entry[1].
  3. Use both values. Index for labels; node for DOM work.
  4. Tip. Works the same on querySelectorAll lists.

Example 3 — querySelectorAll

Static NodeLists from selectors also support entries().

JavaScript
// Imagine: <ul id="fruit"><li>Apple</li><li>Banana</li><li>Cherry</li></ul>
const items = document.querySelectorAll("#fruit li");
const lines = [];

for (const [i, el] of items.entries()) {
  lines.push(i + ": " + el.textContent);
}
console.log(lines.join(", ")); // 0: Apple, 1: Banana, 2: Cherry
Try It Yourself

How It Works

  1. Select elements. querySelectorAll returns a NodeList.
  2. Iterate pairs. Same entries() API as childNodes.
  3. Read text. Use the node half of each pair.
  4. Static list. Unlike live childNodes, this snapshot does not update if the DOM changes later.

Example 4 — Array.from

Materialize the iterator into a real array of pairs.

JavaScript
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
node.appendChild(document.createElement("span"));

const pairs = Array.from(node.childNodes.entries(), ([i, n]) => {
  return [i, n.nodeName];
});

console.log(JSON.stringify(pairs)); // [[0,"P"],[1,"SPAN"]]
Try It Yourself

How It Works

  1. Pass the iterator. Array.from(list.entries()).
  2. Optional map. Second argument transforms each pair.
  3. Get a real array. Useful for map / filter later.
  4. Cost. You copy all pairs into memory — fine for small lists.

Example 5 — vs keys() / values()

See what each iterator yields from the same NodeList.

JavaScript
const node = document.createElement("div");
node.appendChild(document.createElement("p"));
node.appendChild(document.createElement("span"));
const list = node.childNodes;

console.log("keys:", Array.from(list.keys()).join(","));
// 0,1

console.log("values:", Array.from(list.values(), (n) => n.nodeName).join(","));
// P,SPAN

console.log(
  "entries:",
  Array.from(list.entries(), ([i, n]) => i + ":" + n.nodeName).join(",")
);
// 0:P,1:SPAN
Try It Yourself

How It Works

  1. keys() — numbers only.
  2. values() — nodes only.
  3. entries() — both together.
  4. Pick one. Use entries() when you need the index and the node in the same loop.

Browser Support

NodeList.entries() is marked Baseline Widely available on MDN (since October 2017). DOM API — not a Node.js built-in.

✓ Baseline · Widely available

entries()

Iterate [index, node] pairs on NodeList across modern browsers.

98% Core tag support
Chrome 51+
Full support
Edge 16+
Full support
Firefox 50+
Full support
Safari 10+
Full support
Opera 38+
Full support
HTML element 100% supported

Bottom line: Safe for production. Prefer for...of over entries() when you need both the index and the node.

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.
keys() yields indexes only. values() yields Node objects only. entries() yields both as [index, node] pairs.
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.
No. It only iterates existing nodes. It does not add, remove, or mutate nodes by itself.
Modern NodeLists do — including node.childNodes and the list from document.querySelectorAll(...).

Next: forEach()

Run a simple callback for every node in the list.

forEach() →

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.

8 people found this page helpful