Set.prototype.entries()

set.entries()
Returns: Iterator · Updated March 13, 2026 · Map and Set
set entries iteration

The entries() method returns a new Set Iterator containing [value, value] pairs for each value in the Set, in insertion order. This method exists primarily for consistency with the Map API, since Sets don’t have traditional key-value pairs.

Return Type

Set.prototype.entries() returns a new Iterator object that yields [value, value] arrays. Each entry is an array where both the first and second elements are the same—the Set’s value. The iterator maintains the insertion order in which values were added to the Set.

You can consume the iterator using for...of loops, the spread operator [...set.entries()], or by calling next() directly.

Key Quirk

Unlike Map.prototype.entries(), which returns [key, value] pairs where keys and values can differ, Set.prototype.entries() returns [value, value] because Sets only store values, not key-value pairs. This design maintains API consistency with Map while reflecting that Sets have no traditional keys.

const set = new Set(['a', 'b', 'c']);
[...set.entries()];
// [['a', 'a'], ['b', 'b'], ['c', 'c']]

Syntax

set.entries()

Examples

Basic iteration with for…of

const animals = new Set(['dog', 'cat', 'bird']);

for (const [key, value] of animals.entries()) {
  console.log(`${key} -> ${value}`);
}
// dog -> dog
// cat -> cat
// bird -> bird

Manual iteration with next()

const set = new Set([1, 2, 3]);
const iterator = set.entries();

console.log(iterator.next().value); // [1, 1]
console.log(iterator.next().value); // [2, 2]
console.log(iterator.next().value); // [3, 3]
console.log(iterator.next().done);   // true

Comparison with Map.entries()

// Map: distinct key and value
const map = new Map([['a', 1], ['b', 2]]);
console.log([...map.entries()]);
// [['a', 1], ['b', 2]]

// Set: key and value are identical
const set = new Set(['a', 'b']);
console.log([...set.entries()]);
// [['a', 'a'], ['b', 'b']]

See Also