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, coffeeNotes
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
- Map.prototype.values — Returns the values of a Map.
- Map.prototype.entries — Returns the key–value pairs of a Map.
- Array.from — Creates an array from a string, Set, Map or another iterable.
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.