Skip to content

Object.values(): read an object's values (ES2017)

  • What Object.values() returns and how it relates to Object.keys().
  • How to aggregate dictionary-shaped data: totals, any/all checks, unique values.
  • The surprising edge cases: getters running, Maps, array holes, and TypeScript’s any[].
  • When Object.entries() or a Map is the better choice.

TL;DR: Object.values(obj) returns a new array of the values of the object’s own, enumerable, string-keyed properties, in the same order as Object.keys(). It is the right call when the keys are only labels and you care about the data.

It was added in ECMAScript 2017, together with Object.entries(), and is supported by every current browser and runtime (details in Compatibility).

APIs often return dictionaries keyed by ID or SKU. When you only need the values, ES5 code mapped over the keys and looked each value up. The invented OrdersPortal app below stores line totals in cents, keyed by SKU.

Running the samples: save a sample as a .mjs file and run it with Node.js 22 (node sample.mjs), or paste it into a browser console. All outputs shown were produced with Node.js 22.23.

// OrdersPortal: line totals keyed by SKU, in cents.
const lineTotals = { 'A-77': 1999, 'B-12': 4500, 'C-03': 250 };
// Before ES2017: go through the keys and look each value up.
const before = Object.keys(lineTotals).map((sku) => lineTotals[sku]);
console.log(before);
// ES2017: ask for the values directly.
const subtotal = Object.values(lineTotals).reduce((sum, cents) => sum + cents, 0);
console.log(Object.values(lineTotals), subtotal);

Output:

[ 1999, 4500, 250 ]
[ 1999, 4500, 250 ] 6749
// Fragment: signature
const values = Object.values(obj); // any[]

The spec algorithm is ToObject(obj), then EnumerableOwnProperties(obj, value): the same selection and order rules as Object.keys() (explained on the Object.keys page), with null and undefined throwing a TypeError. What differs is that each value is read with an ordinary property get:

  • Getters run. Every enumerable accessor property calls its getter once, with the object as this.
  • The list is checked live. For each key, the engine re-reads the property descriptor just before reading the value. If a getter deletes a later property, that property is skipped; if it adds one, the new key is not visited.
  • Values are not copied. Object values are the same references; mutating them mutates the source.
let reads = 0;
const cart = {
items: 3,
get shipping() { reads++; return 495; }, // getters run
[Symbol('id')]: 'cart-9', // symbols are skipped
};
Object.defineProperty(cart, 'secret', { value: 'x', enumerable: false });
console.log(Object.values(cart), 'getter reads:', reads);
// A getter that deletes a later property: the deleted key is skipped.
const draft = { get a() { delete this.b; return 1; }, b: 2, c: 3 };
console.log(Object.values(draft));
console.log(Object.values('hi'));
console.log(Object.values(new Map([['k', 'v']]))); // Maps store entries internally
console.log(Object.values([10, , 30])); // holes skipped

Output:

[ 3, 495 ] getter reads: 1
[ 1, 3 ]
[ 'h', 'i' ]
[]
[ 10, 30 ]

The typings live in lib.es2017.object.d.ts:

// Fragment: from TypeScript 6.0.3 lib.es2017.object.d.ts
values<T>(o: { [s: string]: T } | ArrayLike<T>): T[];
values(o: {}): any[];

A Record<string, number> or a number[] gives number[]. A type alias such as type Totals = { id: string; total: number } is implicitly indexable, so it gives the union (string | number)[]. An interface with the same members has no implicit index signature, falls through to the second overload and gives any[] (checked with TypeScript 6.0.3). If you need well-typed values, use a Record type for dictionary data, or read named properties directly.

OrdersPortal receives stock levels as a nested dictionary: SKU, then warehouse, then units. The product page needs a total per SKU, whether it is in stock anywhere, and the largest single-warehouse count; the operations dashboard needs to know whether everything is sold out and which carriers are in use.

// OrdersPortal: summarize warehouse stock levels returned as { [warehouseId]: units }.
const stockBySku = {
'A-77': { east: 12, west: 0, central: 4 },
'B-12': { east: 0, west: 0, central: 0 },
'C-03': { east: 7, west: 3 },
};
const summary = Object.values(stockBySku).map((byWarehouse) => {
const counts = Object.values(byWarehouse);
return {
total: counts.reduce((sum, n) => sum + n, 0),
inStockSomewhere: counts.some((n) => n > 0),
max: Math.max(0, ...counts),
};
});
console.log(summary);
const allOutOfStock = Object.values(stockBySku)
.every((byWarehouse) => Object.values(byWarehouse).every((n) => n === 0));
console.log('all out of stock:', allOutOfStock);
// Unique values: combine with a Set.
const carriers = { o1: 'UPS', o2: 'FedEx', o3: 'UPS', o4: 'USPS' };
console.log([...new Set(Object.values(carriers))]);

Output:

[
{ total: 16, inStockSomewhere: true, max: 12 },
{ total: 0, inStockSomewhere: false, max: 0 },
{ total: 10, inStockSomewhere: true, max: 7 }
]
all out of stock: false
[ 'UPS', 'FedEx', 'USPS' ]

Notice what is missing: the summary no longer says which SKU each row belongs to. Once a result needs labels, switch to Object.entries(). The 0 passed to Math.max covers an empty warehouse object, where Math.max() alone returns -Infinity.

  • Losing the key you need later. If the output must say which item a value came from, Object.values() has thrown that information away. Use Object.entries().
  • Triggering expensive or side-effecting getters. Logging Object.values(model) on an object with lazy getters runs all of them. Inspect Object.getOwnPropertyDescriptors() if you need to see accessors without calling them.
  • Calling it on a Map or Set. It returns []. Use [...map.values()].
  • Assuming a deep copy. The array holds the same object references; Object.values(stockBySku)[0].east = 0 changes stockBySku.
  • Spreading a huge array into Math.max. Each element becomes a function argument, and engines cap argument counts: in Node.js 22, spreading two million values throws RangeError: Maximum call stack size exceeded. For very large dictionaries, use reduce instead.
You need Use
Just the values Object.values(obj)
Values plus which key they belong to Object.entries(obj)
Just the keys Object.keys(obj)
Whether one key exists Object.hasOwn(obj, key)
Values of a Map map.values()

Use Object.values() for aggregations where keys are only labels. Prefer a Map when the collection changes constantly or its keys are not strings.

According to MDN’s browser compatibility data, Object.values() is supported in Chrome 54, Edge 14, Firefox 47, Safari 10.1 (iOS 10.3), Node.js 7.0, Deno 1.0 and Bun 1.0. Internet Explorer never supported it. In TypeScript, add es2017 or later to lib only if a project pins an older lib or target; for very old runtimes, core-js provides a polyfill.

1. How is Object.values() different from Object.keys(obj).map((k) => obj[k])? For ordinary data objects the result is the same: same selection rules, same order, getters run in both. The difference shows when a getter changes the object: Object.values() re-checks each property just before reading it, while the keys().map() version reads from a key list taken in advance. With the draft object above, Object.values() gives [1, 3] and the map version gives [1, undefined, 3].

2. What does Object.values() return for an object with a getter, a symbol key and a non-enumerable property? The getter’s return value (the getter runs), and nothing for the symbol key or the non-enumerable property.

3. Senior scenario: a reporting job sums Object.values() over a large dictionary of order totals received from several services, and the totals are occasionally wrong. What do you check? First, the values’ types: one service may send totals as strings, so reduce concatenates instead of adding; validate and convert at the boundary. Second, money representation: sum integer cents, not floating-point dollars. Third, whether some entries are accessors or inherited values that Object.values() skips, and whether duplicate keys from merged payloads overwrote each other before the sum. Log Object.entries() for failing reports so you can see which key carried the bad value.

  • Object.values() (ES2017) returns own, enumerable, string-keyed values in Object.keys() order.
  • Getters run; symbol keys, non-enumerable and inherited properties are skipped.
  • It is ideal for aggregation; switch to Object.entries() when the key matters.
  • Values are references, not copies.