JS: Set.prototype.entries

By Xah Lee. Date: . Last updated: .

New in ES2015.

set_obj.entries ( )

Return a iterator (also is a iterable) 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 JS: Iterator]

Note: Set.prototype.entries is the same as Set.prototype [ Symbol.iterator ]

[see JS: Set.prototype[Symbol.iterator]]

[see JS: Symbol Tutorial]

Reference

ECMAScript 2015 §Keyed Collection#sec-set.prototype.entries

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

Set Topic

  1. JS: the Set Object Tutorial
  2. JS: Set Union, Intersection, Difference
  3. JS: Set Object
  4. JS: Set.prototype
  5. JS: Set.prototype.forEach
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

Ask me question on patreon