HTML DOM NodeList entries() Method

Definition and Usage

The entry() method returns an iterator with key/value pairs from the NodeList.

Example

Example 1

List the entries of the document child nodes:

const list = document.body.childNodes;
for (let x of list.entries()) {
  text += x[0] + " " + x[1];
}

Try it yourself

Example 2

List the names of the document child nodes:

const list = document.body.childNodes;
for (let x of list.entries()) {
  text += x[0] + " " + x[1].nodeName;
}

Try it yourself

Example 3

List the values of the document child nodes:

const list = document.body.childNodes;
for (let x of list.entries()) {
  text += x[0] + " " + x[1].nodeValue;
}

Try it yourself

Example 4

Get the keys of the child nodes of the <body> element:

const list = document.body.childNodes;
for (let x of list.keys()) {
  ... code ...
}

Try it yourself

Example 5

Get the values of the child nodes of the <body> element:

const list = document.body.childNodes;
for (let x of list.values()) {
  ... code ...
}

Try it yourself

Syntax

nodelist.entries()

Parameters

No parameters.

Return Value

Type Description
Object Iterator object with key/value pairs in the list.

Browser Support

nodelist.entries() is a DOM Level 4 (2015) feature.

All modern browsers support it:

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Internet Explorer 11 (or earlier versions) does not support nodelist.entries().

Related Pages

length Property

forEach() Method

item() Method

keys() Method

values() Method

NodeList Object

childNodes() Method

querySelectorAll() Method

getElementsByName() Method