JS: Map.prototype.entries

By Xah Lee. Date: . Last updated: .

New in ES2015.

map_obj.entries ( )

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

[see JS: Iterator]

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

[see JS: Symbol Tutorial]

Reference

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

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

Map Topic

  1. JS: the Map Object Tutorial
  2. JS: Map Object
  3. JS: Map.prototype
  4. JS: Iterate Over Map Object
  5. JS: Convert Object to/from Map
  6. JS: Map Filter
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS Basics
  4. JS in Depth
  5. JS Reference
  6. DOM
  7. SVG
  8. JS Misc