HTML DOM NodeList keys() Method

Definition and Usage

The keys() method returns an Iterator containing the keys of the NodeList.

Example

Example 1

List the keys of the child nodes of the document:

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

Try It Yourself

Example 2

List the child nodes of the document:

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

Try It Yourself

Syntax

nodelist.keys()

Parameters

No parameters.

Return Value

Type Description
Object Iterator object containing the keys of the list.

Browser Support

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

Related Pages

length Property

entries() Method

forEach() Method

item() Method

values() Method

NodeList Object

childNodes() Method

querySelectorAll() Method

getElementsByName() Method