JS: Set.prototype.keys

By Xah Lee. Date: . Last updated: .

(new in ECMAScript 2015)

mySet.keys()
  • Return a Generator.
  • Each yield of the iterator is a element of the set.
const xx = new Set([3, 4]);
for (let k of xx.keys()) {
 console.log(k);
}
// 3
// 4

Verify Result is a Generator

const xx = (new Set([3, 4])).keys();

// is an iterable
console.log(Reflect.has(xx, Symbol.iterator));
// true

// is an iterator
console.log(Reflect.has(xx, "next"));
// true