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
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
@@iterator |
43 |
12 |
36
27-36
A placeholder property named
@@iterator is used.17-27
A placeholder property named
iterator is used. |
No |
30 |
9 |
43 |
43 |
36
27-36
A placeholder property named
@@iterator is used.17-27
A placeholder property named
iterator is used. |
30 |
9 |
4.0 |
See also
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/@@iterator