Map.prototype.values
Returns the values of a Map.
Available since: ES2015
Syntax
map.values()Return value
IteratorAn iterator of the values in insertion order.
Examples
The sum of all values:
const prices = new Map([['tea', 3], ['coffee', 5]]);
let total = 0;
for (const price of prices.values()) {
total += price;
}
console.log(total);Output:
8Notes
Like keys(), it returns an iterator. It is single-use: once fully consumed, it cannot be iterated again.
See also
- Map.prototype.keys — Returns the keys of a Map.
- Map.prototype.entries — Returns the key–value pairs of a Map.
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.