JavaScript: Map.prototype.entries

By Xah Lee. Date: . Last updated: .

New in ES2015.

Map.prototype.entries ( )

Returns a iterator function for the map instance (of this binding).

〔►see JavaScript: “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 JavaScript: Iterator

〔►see JavaScript: Interface

〔►see JavaScript: Symbol Tutorial

Reference

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

Map Topic

  1. JavaScript: the Map Object Tutorial
  2. JavaScript: Map Object
  3. JavaScript: Map.prototype
  4. JavaScript: Iterate Over Map Object
  5. JavaScript: Convert Object to/from Map
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.