inspection
Object.values
Returns an array of a given object's own enumerable string-keyed property values. Introduced in ES2017 as a companion to Object.keys.
Object.values(obj) Parameters
| Parameter | Purpose |
|---|---|
| obj | The object whose enumerable own property values are to be returned |
| returns | Array of own enumerable property values |
Examples
console.log(Object.values({ a: 1, b: 2, c: 3 })); Logs [ 1, 2, 3 ]
const user = { name: 'Ada', age: 36 };
console.log(Object.values(user)); Logs [ 'Ada', 36 ]
const nums = { x: 10, y: 20, z: 30 };
console.log(Object.values(nums).reduce((a, b) => a + b, 0)); Logs 60 — sum of all values
console.log(Object.values('abc')); Logs [ 'a', 'b', 'c' ] — strings are coerced to array-like objects
Gotcha
Order follows the same rule as Object.keys — integer-like keys come first in ascending order, then string keys in insertion order. Symbol-keyed values are excluded.
Related methods
Object.keys
Returns an array of a given object's own enumerable string-keyed property names. The order matches a normal for...in loop but excludes inherited and non-enumerable properties.
Object.entries
Returns an array of a given object's own enumerable string-keyed [key, value] pairs. Useful for iterating objects with for...of destructuring or converting to a Map.
Object.fromEntries
Transforms a list of key-value pairs into an object — the inverse of Object.entries. Introduced in ES2019 and accepts any iterable of [key, value] pairs, including Map.
Object.hasOwn
Returns true if the specified object has the given property as its own property (not inherited). Added in ES2022 as the recommended replacement for Object.prototype.hasOwnProperty.
Object.prototype.hasOwnProperty
Instance method returning true if the object has the specified property as its own (non-inherited) property. Superseded by the safer static Object.hasOwn in ES2022.