JavaScript Reference ยท Object
Object.values()
Reference for JavaScript Object.values(): get an array of an object's own enumerable property values, with ordering rules and edge cases.
Object.values() returns a new array holding the values of an object's own enumerable string-keyed properties. It is the value-only sibling of Object.keys() and Object.entries().
It is handy for summing, filtering or searching the values of a plain object without caring about the keys.
const prices = { tea: 3, coffee: 4 }; Object.values(prices); // [3, 4]
Try it
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Press Run (or Ctrl + Enter) to see the console output here.
No output.
Syntax
Object.values(obj)
| Name | Description |
|---|---|
obj |
The object whose values you want. Primitives are converted to objects first. |
Return value: a new array of the property values, in the same order as Object.keys().
Exceptions: a TypeError if obj is null or undefined.
Usage notes
- Order. Integer-like keys come first in ascending numeric order, then string keys in the order they were created. Symbol keys are skipped.
- Own and enumerable only. Inherited values and properties made non-enumerable (for example with
Object.defineProperty()) are left out. - Snapshot. The array holds the values at the time of the call. Changing the object later does not update it, but object values are still shared references, not clones.
- Getters run. Accessor properties are read, so their getters execute.
- Strings and arrays work. A string gives its characters, and an array gives its elements (including only existing elements of sparse arrays).
- Maps and Sets are not covered:
Object.values(new Map())returns an empty array. Usemap.values()instead. - Need pairs? Use
Object.entries(). Need keys? UseObject.keys().
Browser support
Object.values() is available in every current browser and JavaScript runtime.