JS Built-ins
← Set44 / 85
Setentriesbeginner

Set entries() β€” empty Set

πŸ“– Usage Example
const s = new Set(['a', 'b'])
for (const [key, val] of s.entries()) {
  console.log(key, val) // 'a' 'a', then 'b' 'b'
}

Use Set.entries() to iterate over [value, value] pairs; both elements are the same.

Set.prototype.entries()

entries() on an empty Set produces an empty iterator.

Challenge: Verify that spreading entries() of an empty Set gives an empty array.

πŸ’‘ Hints (1)
  • β€’ An empty Set has no entries to iterate