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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@iterator | ChromeFull support43 | EdgeFull support12 | FirefoxFull support36 | Internet ExplorerNo supportNo | OperaFull support30 | SafariFull support9 | WebView AndroidFull support43 | Chrome AndroidFull support43 | Firefox for AndroidFull support36 | Opera AndroidFull support30 | Safari on iOSFull support9 | Samsung InternetFull support4.0 | DenoFull support1.0 | Node.jsFull support0.12.0 |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- Uses a non-standard name.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.