Map.prototype.values()
map.values() Returns:
Iterator · Updated March 13, 2026 · Map and Set map values iteration
The values() method returns a new Iterator object containing all the values in the Map. The values are returned in the same order they were inserted into the Map.
Syntax
map.values()
Parameters
None.
Return Value
A new Iterator object containing the values of the Map.
Examples
Getting all values as an array
const userRoles = new Map([
['alice', 'admin'],
['bob', 'editor'],
['charlie', 'viewer']
]);
console.log([...userRoles.values()]);
// ['admin', 'editor', 'viewer']
Iterating with for…of
const prices = new Map([
['apple', 1.5],
['banana', 0.75],
['orange', 2.0]
]);
for (const value of prices.values()) {
console.log(`$${value}`);
}
// $1.5
// $0.75
// $2.0
Calculate total from values
const inventory = new Map([
['apples', 50],
['bananas', 30],
['oranges', 25]
]);
const total = [...inventory.values()].reduce((a, b) => a + b, 0);
console.log(total); // 105
Find specific value
const products = new Map([
['sku1', { name: 'Widget', stock: 10 }],
['sku2', { name: 'Gadget', stock: 0 }]
]);
const outOfStock = [...products.values()].find(p => p.stock === 0);
console.log(outOfStock); // { name: 'Gadget', stock: 0 }
Values with forEach
const scores = new Map([
['alice', 95],
['bob', 82],
['charlie', 91]
]);
scores.forEach((value) => {
console.log(`Score: ${value}`);
});
Transform values to array
const data = new Map([
['a', ' hello '],
['b', ' world ']
]);
const trimmed = [...data.values()].map(s => s.trim());
console.log(trimmed); // ['hello', 'world']
Common Patterns
Get unique values as Set
const roles = new Map([
['alice', 'admin'],
['bob', 'editor'],
['charlie', 'admin'],
['dave', 'viewer']
]);
const uniqueRoles = new Set([...roles.values()]);
console.log([...uniqueRoles]); // ['admin', 'editor', 'viewer']
Check if all values pass a test
const temperatures = new Map([
['morning', 72],
['afternoon', 85],
['evening', 78]
]);
const allWarm = [...temperatures.values()].every(t => t > 60);
console.log(allWarm); // true