JavaScript NodeList item() Method

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

What You’ll Learn

The item() method of a NodeList returns a node by zero-based index. Learn how it compares with nodeList[index], what happens when the index is out of range (null), and how to loop with length—with five examples and try-it labs.

01

Kind

Instance method

02

Returns

Node or null

03

Param

Zero-based index

04

Out of range

null

05

Alias

list[i]

06

Status

Baseline widely

Introduction

A NodeList is ordered. When you need one node at a known position, call list.item(index). Indexes start at 0, so item(0) is the first node and item(1) is the second.

In JavaScript you can also write list[index]—MDN treats that as equivalent for reading a node by index. Prefer item() when you want an explicit method call, or when teaching DOM APIs that mirror older collection styles.

💡
Beginner tip

Out of range does not throw—you get null. Calling item() with no argument throws a TypeError.

Understanding the item() Method

An instance method on NodeList that fetches the node at a given index.

  • Parameterindex (zero-based).
  • Returns — the node at that index, or null if out of range.
  • Equivalent in JSnodeList[index].
  • No argument — throws TypeError.
  • Baseline Widely available on MDN (since July 2015).

📝 Syntax

JavaScript
item(index)

Parameters

  • index — the zero-based index of the node to fetch.

Return value

The node at that index, or null if the index is out of range.

Exceptions

TypeError if no argument is provided.

Typical pattern (MDN idea)

JavaScript
const list = document.querySelectorAll("li");
const second = list.item(1); // same idea as list[1]
// first item is index 0; index 1 is the second match

⚡ Quick Reference

GoalCode / note
First nodelist.item(0)
Second nodelist.item(1)
Bracket formlist[1]
Out of rangeReturns null
Loop by indexfor (let i = 0; i < list.length; i++) list.item(i)
MDN statusBaseline Widely available (since July 2015)

🔍 At a Glance

Four facts to remember about NodeList.item().

Returns
Node|null

By index

Index
0-based

First is 0

Missing
null

Out of range

Baseline
widely

Since Jul 2015

Examples Gallery

Examples follow MDN NodeList.item(). Labs use querySelectorAll / childNodes (true NodeLists) and the same index idea as MDN’s sample.

📚 Getting Started

Fetch a node by index.

Example 1 — Read item(1) (MDN Idea)

Get the second match (index 1) from a NodeList.

JavaScript
const list = document.querySelectorAll("li");
const second = list.item(1); // or list[1]
console.log(second && second.textContent);
Try It Yourself

How It Works

MDN’s sample uses index 1 for the second item—same zero-based rule on a NodeList.

Example 2 — item() vs Bracket Access

Confirm both forms return the same node.

JavaScript
const viaItem = list.item(0);
const viaBracket = list[0];
console.log(viaItem === viaBracket);
Try It Yourself

How It Works

In everyday JS, list[i] is shorter; item(i) is the explicit DOM method.

📈 Bounds & Loops

Handle missing indexes and walk the list by length.

Example 3 — Out of Range Returns null

Ask for an index past the end of the list.

JavaScript
console.log(list.length);
console.log(list.item(99)); // null
Try It Yourself

How It Works

Always check for null before reading properties like textContent.

Example 4 — Loop With length + item()

Classic indexed loop over every node.

JavaScript
for (let i = 0; i < list.length; i++) {
  const node = list.item(i);
  console.log(i, node.nodeName);
}
Try It Yourself

How It Works

Useful when you want an old-style index loop, or need to stop early with break.

Example 5 — Safe Access

Guard against null before using the node.

JavaScript
function readItem(list, index) {
  const node = list.item(index);
  return node ? node.textContent : "(missing)";
}

console.log(readItem(list, 0));
console.log(readItem(list, 99));
Try It Yourself

How It Works

A tiny helper keeps call sites safe when the index might be wrong.

🚀 Common Use Cases

  • Grab the first or second match from querySelectorAll.
  • Read a child by position from childNodes.
  • Write indexed for loops with early break.
  • Teach zero-based indexing for DOM collections.
  • Prefer explicit item() in code that mirrors other DOM collection APIs.

🔧 How It Works

1

Get a NodeList

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

DOM
2

Pass an index

Call list.item(i) with a zero-based index.

Call
3

Resolve

In-range indexes return the Node; out-of-range indexes return null.

Result
4

Use safely

Check for null before reading node properties.

📝 Notes

  • MDN: Baseline Widely available (since July 2015) — no Deprecated / Experimental / Non-standard banner.
  • Zero-based index; out of range returns null.
  • No argument → TypeError.
  • In JS, list[i] is equivalent for reading.
  • Related learning: forEach(), entries(), childNodes, JavaScript hub.

Universal Browser Support

NodeList.item() is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project.

Baseline · Widely available

NodeList.item()

Returns the node at a zero-based index, or null if the index is out of range.

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 Supported on NodeList (prefer modern browsers overall)
Legacy OK
NodeList.item() Excellent

Bottom line: Use list.item(i) or list[i] to read one node. Always handle null for out-of-range indexes.

Conclusion

NodeList.item() fetches one node by zero-based index. Out-of-range indexes return null, and in JavaScript list[i] does the same job for reading.

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

💡 Best Practices

✅ Do

  • Remember indexes start at 0
  • Check for null before using the node
  • Use list.length to stay in bounds
  • Prefer list[i] in everyday JS when it is clearer
  • Use item() when you want an explicit method

❌ Don’t

  • Call item() with no argument
  • Assume out-of-range throws (it returns null)
  • Forget that childNodes includes text nodes
  • Use item(1) thinking it is the first node
  • Skip null checks when the index may be wrong

Key Takeaways

Knowledge Unlocked

Five things to remember about NodeList.item()

One node, by zero-based index.

5
Core concepts
⚙️02

Index

starts at 0

Rule
🔒03

OOB

null

Gotcha
📄04

= list[i]

in JS

Alias
🎯05

Baseline

since Jul 2015

Status

❓ Frequently Asked Questions

It returns the node at a zero-based index in the NodeList. If the index is out of range, it returns null.
No. MDN marks NodeList.item() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard.
Yes in JavaScript. MDN notes that nodeList[index] is equivalent to nodeList.item(index) for reading a node by index.
item(index) returns null. It does not throw for an out-of-range index (as long as you did provide an argument).
A TypeError is thrown when no argument is provided.
Yes. item(0) is the first node; item(1) is the second.
Did you know?

MDN’s classic sample uses item(1) for the second item. That zero-based rule surprises beginners often—item(0) is always the first node.

Explore NodeList.keys()

Next up: iterate index keys with for...of.

keys() 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