JS: Map.prototype.entries

By Xah Lee. Date: . Last updated: .

New in ES2015.

map_obj.entries ( )

Returns a iterator function for the map instance map_obj.

〔►see JS: “this” Binding

Map.prototype.entries ( ) is the same as Map.prototype [ Symbol.iterator ]( )

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. (which means, it has a “next” method)

console.log ( mp.entries().next() ); // { value: [ 1, 2 ], done: false }
// result is a IteratorResult object

〔►see JS: Iterator

〔►see JS: Interface

〔►see JS: Symbol Tutorial

Reference

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

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
Like what you read? Buy JavaScript in Depth