JS: Set.prototype.entries

By Xah Lee. Date: . Last updated: .

New in JS2015.

setObj.entries ( )
Return a Iterable Object (also is a Iterator) for the set instance setObj. Each yield is a array of the form [value, value].
const ss = new Set([3,4,"ok"]);

for (let e of ss.entries()) {
 console.log( e, Array.isArray ( e ) );
}
// prints
// [ 3, 3 ] true
// [ 4, 4 ] true
// [ 'ok', 'ok' ] true

This example shows the result is iterator and iterable:

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

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

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

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

[see Symbol Tutorial]

BUY ΣJS JavaScript in Depth