JS: Set.prototype.values

By Xah Lee. Date: . Last updated: .

New in ES2015.

set_obj.values ( )

Return a iterator function for the set instance.

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

[see JS: Iterator]

[see JS: Set.prototype[Symbol.iterator]]

Reference

ECMAScript 2015 §Keyed Collection#sec-set.prototype.values

Set Topic

  1. JS: the Set Object Tutorial
  2. JS: Set Union, Intersection, Difference
  3. JS: Set Object
  4. JS: Set.prototype
  5. JS: Set.prototype.forEach
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Ask me question on patreon