JavaScript: Map.prototype.entries

By Xah Lee. Date: . Last updated: .

New in JS2015.

map_obj.entries ( )
Return a Iterable (also is a Iterator) for the map instance map_obj. Each yield is a array of the form [key, value].
const mm = new Map([[1,2],[3,4]]);

for (let e of mm.entries()) {
 console.log( e, Array.isArray ( e ) );
}
// prints
// [ 1, 2 ] true
// [ 3, 4 ] true

for (let e of mm) {
 console.log( e, Array.isArray ( e ) );
}
// prints
// [ 1, 2 ] true
// [ 3, 4 ] true

This example shows the result is iterator and iterable:

let mp = new Map( [[1,2], [3,4]]);

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

// call it
console.log( mp.entries() ); // MapIterator { [ 1, 2 ], [ 3, 4 ] }
// result is a iterator object

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

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

[see Symbol Tutorial]

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

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Map

prototype