HTML DOM NodeList entries()
❮ The NodeList ObjectExamples
List the entries of a document's child nodes:
const list = document.body.childNodes;
for (let x of list.entries()) {
text += x[0] + " " + x[1];
}
Try it Yourself »
List the names of a document's child nodes:
const list = document.body.childNodes;
for (let x of list.entries()) {
text += x[0] + " " + x[1].nodeName;
}
Try it Yourself »
List the values of a document's child nodes:
const list = document.body.childNodes;
for (let x of list.entries()) {
text += x[0] + " " + x[1].nodeValue;
}
Try it Yourself »
More examples below.
Description
The entries()
method returns an Iterator with the key/value pairs from a
NodeList.
See Also:
Syntax
nodelist.entries()
Parameters
NONE |
Return Value
Type | Description |
Object | An Iterator object with the key/value pairs from the list. |
More examples
Example
Get the keys of the <body> element's child nodes:
const list = document.body.childNodes;
for (let x of list.keys()) {
... code ...
}
Try it Yourself »
Example
Get the values of the <body> element's child nodes:
const list = document.body.childNodes;
for (let x of list.values()) {
... code ...
}
Try it Yourself »
Browser Support
nodelist.entries()
is a DOM Level 4 (2015) feature.
It is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |
nodelist.entries()
is not supported in Internet Explorer 11 (or earlier).
❮ The NodeList Object
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.