[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Set/forEach [Back]  [Original]

Set.prototype.forEach() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Set.prototype.forEach()

Baseline

20157

forEach() Set

function logSetElements(value1, value2, set) {
  console.log(`s[${value1}] = ${value2}`);
}

new Set(["foo", "bar", undefined]).forEach(logSetElements);

// : "s[foo] = foo"
// : "s[bar] = bar"
// : "s[undefined] = undefined"

js
forEach(callbackFn)
forEach(callbackFn, thisArg)

callback

value

key

value

set

thisArg

callbackFn this

undefined

forEach() Set callback undefined

callback 3

  • Set

Set 2 Set Map Array forEach()

thisArg forEach() callback this this undefined this callback this

1 forEach() callback forEach()

forEach() callback Set

Set

Set

js
function logSetElements(value1, value2, set) {
  console.log(`s[${value1}] = ${value2}`);
}

new Set(["foo", "bar", undefined]).forEach(logSetElements);

// Logs:
// "s[foo] = foo"
// "s[bar] = bar"
// "s[undefined] = undefined"

ECMAScript 2027 LanguageSpecification
# sec-set.prototype.foreach


Web Proxy Viewer  |  New URL  |  Original Page