JavaScript entries()
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.
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
Mapobject is empty, thenentries()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: 1key: dog, value: 2key: horse, value: 3key: eagle, value: 4key: bear, value: 5key: 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:
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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