JavaScript: Set.prototype.keys

By Xah Lee. Date: . Last updated: .

New in JS2015.

set_obj.keys ( )
Return a Iterable (also is a Iterator) for the set instance set_obj. Each yield of the iterator is a element of the set.
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 Symbol Tutorial]

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Set

prototype