Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Set.prototype.entries() — an iterator of value pairs

Set.prototype.entries() returns an iterator of [value, value] pairs in insertion order. The first position is not an index: Set stores no separate keys. Consume the iterator with next(), for...of, or spread syntax.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

set.entries()

Set.prototype.entries() takes no arguments and returns a new iterator. Each yielded item is a new two-element array [value, value]. Both positions contain the same value; for an object, they reference the same object rather than copies. This format matches the pairs returned by Map.prototype.entries(), but a Set has no separate keys or indexes.

Elements are visited in insertion order. set.values() and default iteration over set yield individual values, whereas set.entries() yields pairs. The method requires a receiver with internal Set data; calling it on a plain object throws TypeError.

The iterator is not a snapshot: it skips elements deleted before they are visited and can include elements added before iteration finishes. Reading consumes the iterator; after exhaustion, subsequent next() calls have done: true. The method itself does not modify the set.

In the example, the repeated "red" does not create another set element. The first next() retrieves the pair for "red", and [...iterator] collects only the remaining pair for "blue".

Examples

const set = new Set(["red", "blue", "red"]);
const iterator = set.entries();

console.log(JSON.stringify(iterator.next().value));
console.log(JSON.stringify([...iterator]));
console.log(iterator.next().done);

Result

["red","red"]
[["blue","blue"]]
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources