Home JavaScript NodeList JavaScript NodeList Definition
Definition and Usage A NodeList is an array-like list of nodes. The most common source is document.querySelectorAll("li"), which returns a static NodeList of matching elements.
Read length, index with list[0] or item(0), and loop with forEach. Methods such as entries, keys, and values support for...of. Some NodeLists (like childNodes) are live and update when the tree changes.
This page teaches what NodeList is. Method and property guides live under this section.
Not a real Array. NodeList has length and forEach, but not map. Use Array.from(list) when you need full array methods.
Syntax
JavaScript Syntax Working with a NodeList:
const items = document.querySelectorAll("li");
console.log(items.length);
items.forEach(function (el, i) {
console.log(i, el.textContent);
}); Reference
Core Ideas Ideas every NodeList tutorial builds on:
Idea Example Remember Query document.querySelectorAll("li")Static NodeList of matches length list.lengthHow many nodes Index list[0]First node or undefined forEach list.forEach(fn)Loop each node entries list.entries()Index/node pairs Live vs static childNodes vs qSALive lists can change
Code
JavaScript Examples Three short programs that show how NodeList works.
1. length 2. forEach 3. entries Example 1 — Count matches length is the number of nodes in the list.
const items = document.querySelectorAll(".card");
console.log(items.length); How It Works querySelectorAll builds a NodeList.length is how many elements matched.An empty match still returns a NodeList with length 0. Example 2 — Loop with forEach forEach calls your function once per node.
const items = document.querySelectorAll("li");
items.forEach(function (el) {
console.log(el.textContent);
}); How It Works forEach walks each node in order.The callback receives the element. No need to convert to an array for simple loops. Example 3 — Index pairs with entries entries() yields [index, node] pairs for for...of.
for (const [i, el] of items.entries()) {
console.log(i + ":" + el.tagName);
} How It Works entries() returns an iterator.Destructure [i, el] in the loop. Indexes start at 0 like arrays. Continue
Next: NodeList Guides Continue with entries, forEach, and the other list methods.
Look up Why entries() Index/node pairs forEach()Loop each node item()Node at an index keys() / values()Iterators for indexes or nodes
Full lists: entries() .
Frequently Asked Questions What is a NodeList? A NodeList is an array-like collection of DOM nodes, commonly returned by querySelectorAll. It has length and can be looped with forEach.
Is a NodeList an Array? No. It is array-like. Use Array.from(nodeList) or [...nodeList] when you need map, filter, or other array methods.
What is a live NodeList? A live list updates when the document changes. childNodes is live. querySelectorAll returns a static list that does not auto-update.
How do I get the first node? Use list[0] or list.item(0). If the list is empty, both give undefined/null respectively—check length first.
Where should I go next? Open entries() and forEach(), then Document querySelectorAll examples.
Open entries() Then explore forEach, item, keys, and values.
entries() → CODETOFUN NEWS
Stay Ahead in Tech Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
12 people found this page helpful
Helpful Share Copy link Suggestion