Object.values()
ES2017+Returns an array of a given object's own enumerable string-keyed property values, in the same order that Object.keys() lists the keys. It lets you apply array methods like reduce(), filter(), and Math aggregations directly to the data stored in an object without caring about the key names.
Syntax
Object.values(obj)Parameters
obj Object The object whose enumerable own property values are to be returned
Return Value
An array containing the object's own enumerable property values
Examples
const obj = { a: 1, b: 2, c: 3 };
console.log(Object.values(obj)); 📌 When to Use
Use Object.values() when the keys are irrelevant and you only care about the data stored in an object. It shines with objects used as keyed collections — lookup tables, caches, and normalized state shaped like { id: record } — where you frequently need to aggregate, search, or display every record without caring what its key is. Typical jobs include summing prices in a cart object, finding the minimum or maximum reading in a sensor map, counting how many entries satisfy a condition with filter().length, feeding values into Math.max(...Object.values(obj)), and rendering a list from a dictionary of items. It pairs naturally with reduce() for totals and averages, and with some() and every() for validation questions like "is every field filled in?". Choose Object.keys() when you need names and Object.entries() when you need both sides of the pair; picking the narrowest method documents your intent and avoids building throwaway data structures. Note that the returned array holds references to the same nested objects as the source, so mutating an element mutates the original — clone first when you need isolated copies.
⚠️ Common Mistakes
Mutating nested values through the returned array and being surprised the source object changed - the array holds references, not copies. Object.values(state).forEach(item => item.done = true) rewrites the original state objects; use map() with object spreads or structuredClone() when you need independent data to work on.
Passing null or undefined throws a TypeError - unlike an empty object, a missing object crashes the call. Guard optional inputs with Object.values(data ?? {}) so downstream reduce() or forEach() calls simply see an empty array instead of an exception.
Expecting Symbol-keyed or non-enumerable values to appear - Object.values() skips both. Values stored under Symbol keys or defined with enumerable: false are invisible here, which matters when inspecting library objects or class instances that deliberately hide internal state from enumeration.
Forgetting that Object.values() returns values in the same order as Object.keys() - property insertion order, not sorted order.
Not handling null or undefined values in the resulting array - always validate or filter if your object may contain these.
Using Object.values() when you also need keys - use Object.entries() instead to avoid a second iteration.
✅ Best Practices
Aggregate with spread into Math functions for compact min/max logic: Math.max(...Object.values(scores)) - but switch to a reduce() loop when the object may hold thousands of entries, since spreading huge arrays into a function call can exceed engine argument-length limits and throw.
Validate forms and configs with some() and every(): Object.values(form).every(v => v !== "") checks completeness in one line without caring which field is which, and the check stays correct as new fields are added to the form later.
Chain with array methods for powerful transformations: Object.values(prices).reduce((sum, price) => sum + price, 0)
Use with Set for unique values: new Set(Object.values(obj)) to get unique property values.
Prefer Object.values() over Object.keys().map(k => obj[k]) for cleaner, more readable code.
⚡ Performance Notes
Object.values() is O(n) in time and memory: it walks every own enumerable property and materializes a fresh array of value references on each call. That allocation is the real cost — repeated calls in a render loop or inside callbacks create needless garbage-collector pressure, so hoist the result into a variable when the object has not changed between uses. Engines read values fastest from objects with stable hidden classes; objects that have had many properties added and deleted may fall into slower dictionary mode. The array itself contains references, so the call stays cheap even when values are large objects — no deep copying happens. When you need keys and values together, one Object.entries() pass is cheaper than calling Object.keys() and Object.values() separately and indexing them in parallel.
🌍 Real World Example
Shopping Cart Total Calculator
This shopping cart stores products as an object keyed by product name, a common shape for fast lookups and deduplication. Object.values() ignores the keys and hands the item records straight to reduce(), which computes the order total in one pass; a second reduce() finds the most expensive product. The same pattern powers dashboards and reports over any { id: record } data structure: normalize by key for O(1) access, then drop down to values when it is time to aggregate.
const cart = {
apple: { price: 1.50, quantity: 3 },
banana: { price: 0.75, quantity: 6 },
orange: { price: 2.00, quantity: 2 }
};
const total = Object.values(cart)
.reduce((sum, item) => sum + (item.price * item.quantity), 0);
console.log('Total: $' + total.toFixed(2));
// Total: $13.00
// Find the most expensive item
const mostExpensive = Object.values(cart)
.reduce((max, item) => item.price > max.price ? item : max);
console.log('Most expensive: $' + mostExpensive.price);
// Most expensive: $2.00