JavaScript NodeList item() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Method

Definition

NodeList.item() returns one node by zero-based index (MDN). Out of range returns null — it does not throw when you pass an argument.

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

Syntax

Call nodeList.item. Start with this line.

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

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

Library declarations
JavaScript
nodeList.item(index)

Parameters

ParameterDescription
indexRequired. Zero-based position

Return Value

Return ValueDescription
*The node at that index
*null

JavaScript Examples

Example 1 — Basic item(0)

Read the first child node by index.

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

const first = node.childNodes.item(0);
console.log(first.nodeName); // P
Try It Yourself

How It Works

  1. Create a parent. Append two element children.
  2. Call item(0). Index 0 is the first node.
  3. Read nodeName. Confirms you got the <p>.
  4. Tip. Same idea as list[0] in JavaScript.

Example 2 — Second Node

MDN idea: item(1) returns the second entry (zero-based).

JavaScript
// Imagine: <ul id="fruit"><li>Apple</li><li>Banana</li><li>Cherry</li></ul>
const list = document.querySelectorAll("#fruit li");
const second = list.item(1);
console.log(second.textContent); // Banana
Try It Yourself

How It Works

  1. Select list items. querySelectorAll returns a NodeList.
  2. Call item(1). Second item — not the first.
  3. Read text. Banana is at index 1.
  4. Static list. Unlike live childNodes, this snapshot does not grow later.

Example 3 — Out of Range

An index past the end returns null, not an exception.

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

const list = node.childNodes;
const missing = list.item(5);

console.log(missing);            // null
console.log(missing === null);   // true
Try It Yourself

How It Works

  1. One child only. Valid indexes are 0 alone.
  2. Call item(5). Past the end.
  3. Get null. Safe to check before use.
  4. No throw. MDN: exceptions are avoided when an argument is provided.

Example 4 — vs Brackets

In JavaScript, list[i] reads the same node — missing values differ.

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

console.log(list.item(0).nodeName); // P
console.log(list[0].nodeName);      // P
console.log(list.item(9));          // null
console.log(list[9]);               // undefined
Try It Yourself

How It Works

  1. In range. item(0) and list[0] match.
  2. Out of range. item → null; brackets → undefined.
  3. Pick a check. Use === null with item, or truthy checks carefully.
  4. Why item? Useful in non-JS DOM APIs; clear method name in tutorials.

Example 5 — Loop with length

Classic index loop: item(i) from 0 to length - 1.

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

const list = node.childNodes;
const names = [];
for (let i = 0; i < list.length; i++) {
  names.push(list.item(i).nodeName);
}
console.log(names.join(", ")); // P, #text, SPAN
Try It Yourself

How It Works

  1. Use length. Upper bound for the loop.
  2. Call item(i). Safe while i < length.
  3. Collect names. Same order as insertion.
  4. Modern tip. Prefer forEach() or for...of for everyday walks.

Browser Support

NodeList.item() is marked Baseline Widely available on MDN (since July 2015). DOM API — not a Node.js built-in.

✓ Baseline · Widely available

item()

Read a NodeList entry by zero-based index across modern browsers.

99% Core tag support
Chrome 1+
Full support
Edge 12+
Full support
Firefox Yes
Full support
Safari Yes
Full support
Opera Yes
Full support
HTML element 100% supported

Bottom line: Safe for production. Prefer item(i) or list[i] for one node; use forEach / for...of for full walks.

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 for reading a node. One difference: out of range, item() returns null while brackets return undefined.
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.

Next: keys()

Iterate only the indexes of a NodeList.

keys() →

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