Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

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:

8

Notes

Like keys(), it returns an iterator. It is single-use: once fully consumed, it cannot be iterated again.

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.