JS Built-ins
← Set27 / 85
Setclearbeginner

Set clear() β€” returns undefined

πŸ“– 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()

clear() returns undefined.

Challenge: Verify that the return value of clear() is undefined.

πŸ’‘ Hints (1)
  • β€’ clear() returns undefined β€” it modifies the Set in place