Map.prototype.entries
Returns the key–value pairs of a Map.
Available since: ES2015
Syntax
map.entries()Return value
IteratorAn iterator of [key, value] pairs.
Examples
Pairs as an array:
const map = new Map([['a', 1], ['b', 2]]);
console.log(JSON.stringify([...map.entries()]));Output:
[["a",1],["b",2]]Notes
The loop for (const [key, value] of map) iterates over the same pairs, so entries() is rarely called explicitly.
See also
- Map.prototype.keys — Returns the keys of a Map.
- Map.prototype.forEach — Calls a function for each entry of a Map.
- Object.fromEntries — Creates an object from a list of key–value pairs.
In the tutorial
- Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.