JS: Set.prototype.keys

By Xah Lee. Date: .

New in ES2015.

set_obj.keys ( )

Return a iterator (also is a iterable) for the set instance set_obj.

Each yield of the iterator is a element of the set instance set_obj.

const ss = new Set([3,4,"ok"]);

for (const e of ss.keys()) {
 console.log ( e );
}
// prints
// 3
// 4
// ok

This example shows the result is iterator and iterable:

const ss = new Set( [3,"yes"]);

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

// call it
console.log ( ss.keys() ); // SetIterator { 3, 'yes' }
// result is a iterator object

// is also a iterable
console.log (
 Symbol.iterator in ( ss.keys() )
); // true

[see JS: Iterator]

[see JS: Symbol Tutorial]

Reference

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

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

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog