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 (ECMA-262)
The definition of 'Set.prototype[@@iterator]' in that specification.

Browser compatibility

DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
@@iteratorChrome Full support 43Edge Full support 12Firefox Full support 36
Full support 36
No support 27 — 36
Notes Alternate Name
Notes A placeholder property named @@iterator is used.
Alternate Name Uses the non-standard name: @@iterator
No support 17 — 27
Notes Alternate Name
Notes A placeholder property named iterator is used.
Alternate Name Uses the non-standard name: iterator
IE No support NoOpera Full support 30Safari Full support 9WebView Android Full support 43Chrome Android Full support 43Firefox Android Full support 36
Full support 36
No support 27 — 36
Notes Alternate Name
Notes A placeholder property named @@iterator is used.
Alternate Name Uses the non-standard name: @@iterator
No support 17 — 27
Notes Alternate Name
Notes A placeholder property named iterator is used.
Alternate Name Uses the non-standard name: iterator
Opera Android Full support 30Safari iOS Full support 9Samsung Internet Android Full support 4.0nodejs Full support 0.12

Legend

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

See also