W3cubDocs

/Web APIs

HighlightRegistry: entries() method

Baseline 2025
Newly available

Since ⁨June 2025⁩, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

The entries() method of the HighlightRegistry interface returns a new Iterator object that contains the [name, highlight] pairs for each element in the HighlightRegistry object, in insertion order.

HighlightRegistry is a Map-like object, so this is similar to using Map.entries().

Syntax

entries()

Parameters

None.

Return value

A new iterator object that contains an array of [name, highlight] for each Highlight object in the HighlightRegistry, in insertion order.

Examples

The code snippet below creates and registers two new highlights, and then logs the highlights and their names by using the iterator returned by the entries() method:

const myHighlight1 = new Highlight();
const myHighlight2 = new Highlight();

CSS.highlights.set("first-highlight", myHighlight1);
CSS.highlights.set("second-highlight", myHighlight2);

const iter = CSS.highlights.entries();

console.log(iter.next().value); // ['first-highlight', Highlight]
console.log(iter.next().value); // ['second-highlight', Highlight]

The following code example shows how to iterate over the highlights in the registry by using a for...of loop:

const myHighlight1 = new Highlight();
const myHighlight2 = new Highlight();

CSS.highlights.set("first-highlight", myHighlight1);
CSS.highlights.set("second-highlight", myHighlight2);

for (const [name, highlight] of CSS.highlights.entries()) {
  console.log(`Highlight ${name}`, highlight);
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
entries 105 105 140 91 17.2 105 140 72 17.2 20.0 105 17.2

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HighlightRegistry/entries