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]

JS Set

  1. Set Tutorial
  2. Union, Intersection, Difference

Like it? Help me by telling your friends. Or, 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. CSS
  3. JavaScript
  4. JS Obj Ref
  5. DOM
  6. SVG
  7. Blog