Set.prototype[@@iterator]()

The initial value of the @@iterator property is the same function object as the initial value of the values property.

Syntax

mySet[Symbol.iterator]

Return value

The Set iterator function, which is the values() function by default.

Examples

Using [@@iterator]()

const mySet = new Set();
mySet.add('0');
mySet.add(1);
mySet.add({});

const setIter = mySet[Symbol.iterator]();

console.log(setIter.next().value); // "0"
console.log(setIter.next().value); // 1
console.log(setIter.next().value); // Object

Using [@@iterator]() with for..of

const mySet = new Set();
mySet.add('0');
mySet.add(1);
mySet.add({});

for (const v of mySet) {
  console.log(v);
}

Specifications

Specification
ECMAScript Language Specification
# sec-set.prototype-@@iterator

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
ChromeEdgeFirefoxInternet ExplorerOperaSafariWebView AndroidChrome AndroidFirefox for AndroidOpera AndroidSafari on iOSSamsung InternetDenoNode.js
@@iterator

Legend

Full support
Full support
No support
No support
See implementation notes.
Uses a non-standard name.

See also