The Javascript Set @@iterator property returns iterator.
Its initial value is the same function object as the initial value of the values property.
mySet[Symbol.iterator]
const mySet = new Set();/*w ww . j ava2 s .c om*/ mySet.add('0'); mySet.add(1); mySet.add('1'); mySet.add({}); const setIter = mySet[Symbol.iterator](); console.log(setIter.next().value); console.log(setIter.next().value); console.log(setIter.next().value); console.log(setIter.next().value);
Using [@@iterator]() with for..of
const mySet = new Set();//w ww.j a v a2s. com mySet.add('0'); mySet.add('1'); mySet.add(1); mySet.add({}); for (const v of mySet) { console.log(v); }