JavaScript Map entries() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Map

Definition

map.entries() returns an iterator of [key, value] arrays, one pair per entry, in the order the keys were added. The default iterator of a Map is the same as entries(), so for (const [k, v] of map) and for (const [k, v] of map.entries()) do the same work. Keys can be any value (SameValueZero).

Remember
map.entries()  → iterator of [key, value]

for (const [k, v] of map)           → same as entries()
for (const [k, v] of map.entries()) → explicit

Object.fromEntries(map)  → plain object (string keys)
[...map.entries()]       → array of pairs

Syntax

Call it on a Map. It takes no arguments and is usually used with for...of and destructuring.

JavaScript
map.entries()
CallWhat it does
map.entries()An iterator of [key, value] pairs.
for (const [k, v] of map)The short form: a Map is iterable via entries by default.
Object.fromEntries(map)Build a plain object from the pairs (keys become strings).

Built into JavaScript since ES2015. For values alone, see values(). For keys alone, see keys().

Library declarations
JavaScript
map.entries()   // returns a Map Iterator of [key, value]

// no parameters
// default @@iterator of Map is entries

Parameters

ParameterDescription
(none)This method takes no parameters. Call it as map.entries().

Return Value

Return ValueDescription
Map IteratorAn iterator where each step yields a two-element array [key, value], in insertion order.

JavaScript Examples

Example 1 — Loop Over Pairs with Destructuring

Print every key and value with for...of and array destructuring.

JavaScript
const ages = new Map();
ages.set("Ann", 31);
ages.set("Bob", 27);

for (const [name, age] of ages.entries()) {
  console.log(name + ": " + age);
}
Try It Yourself

How It Works

  1. Each step is a pair. ages.entries() yields ["Ann", 31], then ["Bob", 27].
  2. Destructuring splits the pair. [name, age] pulls the key into name and the value into age.
  3. Insertion order. Pairs come out in the order the keys were added.

Example 2 — for...of on a Map Uses entries()

Compare a plain loop over the Map with an explicit entries() loop.

JavaScript
const tags = new Map();
tags.set("a", 1);
tags.set("b", 2);

const plain = [];
for (const pair of tags) {
  plain.push(pair[0] + "=" + pair[1]);
}

const explicit = [];
for (const pair of tags.entries()) {
  explicit.push(pair[0] + "=" + pair[1]);
}

console.log(plain.join(", "));     // a=1, b=2
console.log(explicit.join(", "));  // a=1, b=2
console.log(plain.join() === explicit.join());  // true
Try It Yourself

How It Works

  1. A Map is iterable. for (const pair of tags) walks the default iterator.
  2. Default means entries. That default iterator is the same as tags.entries().
  3. Same pairs both ways. Both loops build the same list, so the joined strings match.

Example 3 — Build a Plain Object

Turn Map pairs into a plain object with Object.fromEntries().

JavaScript
const scores = new Map();
scores.set("Ann", 10);
scores.set("Bob", 20);

const obj = Object.fromEntries(scores.entries());
console.log(obj.Ann);                 // 10
console.log(obj.Bob);                 // 20
console.log(JSON.stringify(obj));     // {"Ann":10,"Bob":20}
Try It Yourself

How It Works

  1. fromEntries reads the pairs. It walks the entries iterator and builds property names from the keys.
  2. String keys become properties. obj.Ann and obj.Bob hold the same numbers as the Map.
  3. The Map is unchanged. A new object was created. The Map still has its own entries.

Browser & Runtime Support

Map.prototype.entries() is part of ES2015 (ES6), together with keys(), values(), and the Map default iterator.

✓ Baseline · ES2015

Map.prototype.entries()

Works in every modern browser, plus Node.js, Deno, and Bun.

98% Modern browser support
Google Chrome 36+ · Desktop & Mobile
Full support
Mozilla Firefox 6+ · Desktop & Mobile
Full support
Apple Safari 8+ · macOS & iOS
Full support
Microsoft Edge 12+
Full support
Node.js 0.12+ · every current release
Supported
Deno All releases
Supported
Internet Explorer IE 11 · no constructor argument
Basic
Map.prototype.entries() Excellent

Bottom line: Safe to use in any modern browser and runtime. entries() has been part of Map since ES2015.

Frequently Asked Questions

An iterator of [key, value] arrays, one pair per entry, in insertion order.
Yes. The default iterator of a Map is entries(), so a plain for...of walks the same pairs.
Use keys() or values(). entries() always gives both.
Yes. Object.fromEntries(map) or Object.fromEntries(map.entries()) builds an object. Keys become strings.
No. It returns a live iterator. Call it again when you need a second full walk.

Next: forEach()

Prefer a callback over a loop? Try forEach() next.

forEach() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful