JavaScript entries()

Anonymous contributor's avatar
Anonymous contributor
Published Oct 14, 2025
Contribute to Docs

The entries() method in JavaScript Maps returns an iterator containing each key–value pair in insertion order.

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

map.entries();

Parameters:

The .entries() method takes no parameters.

Return value:

An iterator object that contains the [key, value] pairs for each element in the Map, in insertion order.

Note: If the Map object is empty, then entries() returns an empty iterator object.

Example

In this example, a Map’s key-value pairs are iterated using for...of:

const animals = new Map([
['cat', 1],
['dog', 2],
['horse', 3],
['eagle', 4],
['bear', 5],
['coyote', 6],
]);
const iterator = animals.entries();
for (const [key, value] of iterator) {
console.log(`key: ${key}, value: ${value}`);
}

The output produced will be:

key: cat, value: 1
key: dog, value: 2
key: horse, value: 3
key: eagle, value: 4
key: bear, value: 5
key: coyote, value: 6

Codebyte Example

In this example, a Map is used to track car inventory, search for a specific car, and update the inventory and wallet when a purchase is made:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
    • Includes 34 Courses
    • With Professional Certification
    • Beginner Friendly.
      115 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours