Object.values
Returns an array of an object's property values.
Available since: ES2017
Syntax
Object.values(obj)Parameters
| Parameter | Type | Description |
|---|---|---|
| obj | object | The object whose values you need. |
Return value
ArrayAn array of the object's own property values.
Examples
Property values:
const prices = { tea: 3, coffee: 5, cake: 7 };
console.log(Object.values(prices));Output:
[
3,
5,
7
]The sum of all values:
const prices = { tea: 3, coffee: 5, cake: 7 };
console.log(Object.values(prices).reduce((sum, price) => sum + price, 0));Output:
15Notes
The order is the same as in Object.keys(): integer-like keys in ascending order first, then the rest in insertion order.
See also
- Object.keys — Returns an array of an object's property names.
- Object.entries — Returns an array of property name and value pairs.
- Array.prototype.reduce — Reduces an array to a single value.
Related recipes
In the tutorial
- Iterating objects and Object functions — How to iterate over an object in JavaScript: Object.keys, Object.values, Object.entries, Object.fromEntries, for...in and Object.hasOwn.