JavaScript: Set.prototype.entries

By Xah Lee. Date: . Last updated: .

New in JS2015.

set_obj.entries ( )
Return a Iterable (also is a Iterator) for the set instance set_obj. 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]

ECMAScript 2015 §Keyed Collection#sec-set.prototype-@@iterator

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Set

prototype