JS: Set.prototype.values

By Xah Lee. Date: . Last updated: .

New in JS2015.

setObj.values ( )
Return a Iterator function for the set instance. 〔see Iterator
const ss = new Set ([3,4,5]);

console.log( ss.values ); // [Function: values]
// result is a function, and this function returns a iterator object

// call it
console.log( ss.values() ); // SetIterator { 3, 4, 5 }
// result is a iterator object. (which means, it has a “next” method)

console.log( ss.values().next() ); // { value: 3, done: false }
// result is a IteratorResult object

set_obj[Symbol.iterator]

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

const ss = new Set();
console.log(ss[Symbol.iterator] === ss.values); // true