# Set.entries()

> The `.entries()` JS method returns a new `Iterator` object with [value, value] pairs for each element in the set, where both the key and value are the same.

## Why does Set entries() return pairs with the same value twice?

The method that returns an iterator object containing an array of `[value, value]` pairs for each element in the `Set` object. Since a `Set` object only stores unique values without associated keys, the value is repeated in each pair. This design keeps the API similar to that of the `Map` object.

- Topic: Set
- Type: method
- Browser support: Chrome 38+, Chrome Android 38+, Edge 12+, Firefox 24+, Firefox Android 24+, Safari 8+, Safari iOS 8+

## Example

Wrong:

```js
for (const [i, tag] of tags.entries()) {
  console.log(i, tag);
}
```

Right:

```js
for (const [i, tag] of [...tags].entries()) {
  console.log(i, tag);
}
```

Set entries are `[value, value]`, so `i` was the tag itself; converting to an array gives real indexes.

## Common mistakes

- Expecting `entries()` to return indexes like `Array.prototype.entries()`.

## Key points

- Code that needs only values iterates the set directly or uses `values()`, not `entries()`.
- The first item of each pair is not treated as an index or key.

## Interview questions

### Why does Set have `entries()` at all?

For a shared interface with `Map`, so code that iterates `[key, value]` pairs works on both.

### Is `set.entries()` an array?

No. It returns an iterator; spread it or use `Array.from()` to get an array of pairs.

## Related cards

- [Set.values()](https://wonderium.dev/js/set-values.md)
- [Set.keys()](https://wonderium.dev/js/set-keys.md)
- [Map.entries()](https://wonderium.dev/js/map-entries.md)
- [Array.entries()](https://wonderium.dev/js/array-entries.md)
- [Iterator](https://wonderium.dev/js/iterator.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/set-entries
- Last updated: 2026-11-25
