JS Built-ins
← Set49 / 85
SetforEachbeginner

Set forEach() β€” empty Set is fine

πŸ“– Usage Example
const s = new Set([1, 2, 3])
s.forEach(val => console.log(val))
// 1, 2, 3

Use Set.forEach() to execute a callback for each value in the set.

Set.prototype.forEach()

Calling forEach on an empty Set does not invoke the callback.

Challenge: Verify forEach on empty Set calls callback 0 times.

πŸ’‘ Hints (1)
  • β€’ forEach on an empty Set is a no-op