Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

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

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.

Thanks for reading!

Donate to the site — we work hard for you.