JS: Set.prototype.keys

By Xah Lee. Date: . Last updated: .

(new in JS: ECMAScript 2015)

mySet.keys()
  • Return a Generator.
  • Each yield of the iterator is a element of the set.
console.log(
  JSON.stringify(Array.from(
    (new Set([3, 4])).keys(),
  )) === `[3,4]`,
);
// true

Verify Result is a Generator

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

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

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

JavaScript. Iteration on Set