Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Map.prototype.keys

Returns the keys of a Map.

Available since: ES2015

Syntax

map.keys()

Return value

IteratorAn iterator of the keys in insertion order.

Examples

The keys as an array:

const prices = new Map([['tea', 3], ['coffee', 5]]);
 
console.log([...prices.keys()].join(', '));

Output:

tea, coffee

Notes

The result is an iterator, not an array. To use map() or filter(), turn it into an array with spread or Array.from() first.

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.