Map.prototype.values()
map.values() The values() method returns a new Iterator object containing all the values in the Map, in insertion order. It is one of three iteration methods on Map — alongside keys() and entries() — and is the right choice when you need to process values without caring which keys they belong to.
The iterator is lazy: it does not snapshot the Map’s values upfront. If you add or delete Map entries while iterating, the iterator may visit new entries or skip deleted ones depending on when the modification happens.
Syntax
map.values()
Parameters
None.
Return value
A new Iterator object that yields each value in the Map in insertion order.
The examples below demonstrate the most common ways to consume the values iterator — collecting values into arrays, looping with for...of, and chaining into array methods like reduce, find, and 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']
Spreading the iterator with ... into an array literal is the quickest way to get all Map values as a plain array. Once you have an array, every Array.prototype method becomes available — you can map, filter, reduce, or find without changing how the Map stores its data. The next examples show iteration patterns that avoid creating an intermediate array when you only need to visit each value once.
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
A for...of loop over values() gives you each value directly without the key. This is cleaner than iterating with entries() and destructuring when the key would go unused. The next example shows what happens when you need to combine all values into a single result.
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
Spreading the iterator into an array first lets you use all Array.prototype methods against the values. The find method is especially useful with Map values that are objects — you can locate an entry by a property on the stored object without knowing its key ahead of time.
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 }
If you do not need to build an intermediate array, Map.prototype.forEach visits each value in insertion order using a callback. Unlike for...of, forEach does not expose a break or continue mechanism — it runs to completion for every entry. This is fine for logging, side effects, and display code where you always want to process every value.
Values with forEach
const scores = new Map([
['alice', 95],
['bob', 82],
['charlie', 91]
]);
scores.forEach((value) => {
console.log(`Score: ${value}`);
});
Note that Map.prototype.forEach provides (value, key, map) — the value is the first argument, matching the common convention. When you only need to transform each value without filtering, combining the spread operator with map() gives you a new array in a single expression.
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']
The next two patterns show how values() feeds into common data-processing tasks. Deduplicating values with a Set and testing all values with every() are both one-liners once you have the values as an iterable — the iterator plugs directly into any constructor or method that accepts an iterable argument.
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']
Passing the values iterator to the Set constructor is a concise way to deduplicate values that may appear multiple times across different keys. For validation workflows, every() lets you confirm that all stored values satisfy a condition without writing an explicit loop or keeping a separate flag to track failures.
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
values() vs entries() vs keys()
The three iteration methods give you different slices of the Map’s contents. Use values() when you only care about what is stored, not which keys it’s under. Use keys() when you need to know the identifiers. Use entries() when you need both together, for example when rebuilding a transformed Map:
const prices = new Map([['apple', 1.0], ['banana', 0.5]]);
// Multiply all prices by 1.2 and rebuild the map
const inflated = new Map(
[...prices.entries()].map(([k, v]) => [k, v * 1.2])
);
console.log([...inflated.values()]); // [1.2, 0.6]
If you do not need the keys at all, values() is cleaner than entries() and avoids destructuring that you would then ignore.
Ordering guarantee
Values are returned in insertion order. Adding a key updates its value without changing its position in the iteration sequence. This means if you iterate values() twice without modifying the Map between iterations, you get the same sequence both times.
When values() is the better fit
values() is the simplest iterator to use when the keys do not matter and you only want the stored data. That makes it useful for totals, summaries, and display code that cares about the content but not the labels attached to it.
It is also a good choice when you plan to hand the data to array methods. Converting the iterator with spread or Array.from() gives you a plain list that is easy to map, filter, or reduce.