JS Built-ins
← Set30 / 85
Setclearbeginner

Set clear() β€” clear empty Set

πŸ“– Usage Example
const s = new Set([1, 2, 3])
s.clear()
console.log(s.size) // β†’ 0

Use Set.clear() to remove all values from the set.

Set.prototype.clear()

Calling clear() on an already empty Set is safe.

Challenge: Verify that clearing an empty Set doesn't throw.

πŸ’‘ Hints (1)
  • β€’ clear() is safe to call on an empty Set