JS Built-ins
← Set48 / 85
SetforEachintermediate

Set forEach() β€” third arg is Set

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

The third argument to the callback is the Set itself.

Challenge: Verify that the callback receives the Set as third arg.

πŸ’‘ Hints (1)
  • β€’ Third argument lets you reference the Set inside the callback