JS: Set.prototype.values

By Xah Lee. Date: . Last updated: .

(new in JS: ECMAScript 2015)

Set.prototype.values

mySet.values()

Return a Generator for the entries.

// call it
const xx = (new Set([3, 4, 5])).values();

console.log(JSON.stringify(Array.from(xx)) === `[3,4,5]`);
// true

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

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

Set.prototype[Symbol.iterator]

mySet[Symbol.iterator] is the same as mySet.values.

const xx = new Set();
console.log(xx[Symbol.iterator] === xx.values);

JavaScript. Iteration on Set