DOMTokenList: entries() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.
Theentries() method of theDOMTokenList interfacereturns aniterator allowing youto go through all key/value pairs contained in this object. The values areArrays which have [key, value] pairs, each representing a single token.
In this article
Syntax
entries()Parameters
None.
Return value
Returns aniterator.
Examples
In the following example we retrieve the list of classes set on a<span> element as aDOMTokenList usingElement.classList. We when retrieve an iterator containing the key/valuepairs usingentries(), then iterate through each one using afor...of loop, writing them to the<span>'sNode.textContent.
First, the HTML:
<span></span>Now the #"span");const classes = span.classList;const iterator = classes.entries();for (const value of iterator) { span.textContent += `(${value})`;}
The output looks like this: