JavaScript: Set.prototype.keys
New in JS2015.
setObj.keys ( )
- Return a Iterable Object (also is a Iterator) for the set instance setObj. 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]