Object.values()

The half of the keys/values/entries trio you want when the keys are irrelevant — totalling a record of amounts, or checking whether any field is set.

Object static methodES2017Live demo
Common call
Object.values(obj)
Returns
an array of own enumerable values
Replaces
Object.keys(obj).map(k => obj[k])
Watch out
same integer-key reordering as Object.keys
Object.values(objectobject — Any object. Primitives are coerced; null and undefined throw TypeError.type: object · required)
→ any[]

Demo

Live evaluation
Try:
Inputs
jsonstringa JSON object, e.g. {"a":1}
Output
Object.values(JSON.parse('{"a":1,"b":2}'))
[1, 2]

Values come back in key order, which is why the second case matters: the property written first is returned SECOND, because its sibling has an integer-like key and those are always listed first. If you are pairing values against a separately-computed list of keys, that reordering will silently misalign them — use Object.entries, which keeps each key attached to its value. Nested objects are returned as references, not copied or flattened.

Parameters

NameTypeRequiredDescription
objectobjectyesAny object. Primitives are coerced; null and undefined throw TypeError.

Return value

any[] — The object own enumerable property values, in exactly the order Object.keys would list their keys.

Common patterns

Total a record of numbers
The keys carry no information here.
const total = Object.values(amounts).reduce((a, b) => a + b, 0);
Check whether any field is set
Array methods become available.
const anyFilled = Object.values(form).some(Boolean);
Turn a keyed store into a list
Common when normalising state for rendering.
const list = Object.values(byId);

Examples

1. Own values
Object.values({a: 1, b: 2})
Returns
[1, 2]
2. Key order applies
Object.values({b: 'x', 1: 'y'})
Returns
['y', 'x']
3. An array
Object.values([10, 20])
Returns
[10, 20]
4. A string
Object.values('ab')
Returns
['a', 'b']
5. null throws
Object.values(null)
Returns
TypeError: Cannot convert undefined or null to object
6. Empty object
Object.values({})
Returns
[]

Pitfalls

1. The order is key order, not insertion order
Exactly the same reordering as Object.keys — integer-like keys first, numerically. Zipping these values against an independently built key list, or assuming the first property comes first, breaks as soon as any key looks like a number.
Reordered
Object.values({b: 'first', 1: 'second'})
['second', 'first']
Keep pairs together
Object.entries({b: 'first', 1: 'second'})
[['1', 'second'], ['b', 'first']]
2. Nested values are references
The array is new; the values in it are not copies. Mutating an object taken from the result changes it inside the original too, which surprises people who think of this as a snapshot.
Shared
const src = {a: {x: 1}};
Object.values(src)[0].x = 9;
src.a.x
9
Copy deliberately
structuredClone(src)
independent
3. null and undefined throw
Same as the rest of the family. Any object that might be absent needs a fallback before the call.
Throws
Object.values(maybeNull)
TypeError: Cannot convert undefined or null to object
Fallback
Object.values(maybeNull ?? {})
[]
4. Non-enumerable and symbol-keyed values are omitted
As with keys. A class instance with properties defined via defineProperty, or a library object using symbol keys, will look emptier than it is.
Missing
const o = {};
Object.defineProperty(o, 'h', {value: 1});
Object.values(o)
[]
Descriptors show all
Object.getOwnPropertyDescriptors(o)
includes h

When to use

Use it
  • Aggregating — sums, averages, maxima over a keyed record
  • Testing whether any or every value satisfies a condition
  • Converting a keyed store into a list for rendering
Reach for something else
  • You need the keys too → Object.entries
  • You need only the keys → Object.keys
  • The order must be insertion order → a Map
  • You want a deep copy → structuredClone

Notes

Complexity
O(n) in the number of own enumerable properties
Return
A new array; the values inside are references, not copies
CPython impl
V8: Builtins-object-values
Memory
Allocates the array only
Thread-safe
Single-threaded; the object is only read

FAQ

Yes. All three of keys, values and entries use the same ordering algorithm, so the nth value corresponds to the nth key. What is not guaranteed is that the order matches how you wrote the object — integer-like keys jump to the front.

History

ES2017
Object.values and Object.entries added, completing the trio begun by Object.keys in ES5.