JS Built-ins
← Set37 / 85
Setkeysbeginner

Set keys() β€” spread to array

πŸ“– Usage Example
const s = new Set([1, 2, 3])
for (const k of s.keys()) {
  console.log(k) // 1, 2, 3
}

Use Set.keys() to iterate over the values of a set (identical to values()).

Set.prototype.keys()

Spread keys() to get all values as an array.

Challenge: Verify that [...set.keys()] gives the correct array.

πŸ’‘ Hints (1)
  • β€’ keys() for Set yields the same values as values()