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
BCD tables only load in the browser