docs/reference/compat/object/values.md
::: warning Use Object.values instead
This values function simply calls Object.values with unnecessary overhead.
Use the faster and more modern Object.values() directly instead.
:::
Returns an array of the object's own enumerable property values.
const valueArray = values(obj);
values(obj)Use values when you want to get all property values of an object as an array. It works the same as Object.values but safely handles null or undefined.
import { values } from 'es-toolkit/compat';
// Get object values
const obj = { a: 1, b: 2, c: 3 };
values(obj); // => [1, 2, 3]
// Object with numeric keys
const numberKeyObj = { 0: 'a', 1: 'b', 2: 'c' };
values(numberKeyObj); // => ['a', 'b', 'c']
Can also handle arrays or array-like objects.
import { values } from 'es-toolkit/compat';
// Array
values([1, 2, 3]); // => [1, 2, 3]
// String (array-like object)
values('hello'); // => ['h', 'e', 'l', 'l', 'o']
null or undefined are treated as empty arrays.
import { values } from 'es-toolkit/compat';
values(null); // => []
values(undefined); // => []
Only enumerable properties are returned.
import { values } from 'es-toolkit/compat';
const obj = Object.create(
{ inherited: 'not included' },
{
own: { value: 'included', enumerable: true },
nonEnum: { value: 'not included', enumerable: false },
}
);
values(obj); // => ['included']
obj (Record<PropertyKey, T> | ArrayLike<T> | null | undefined): The object to get property values from.(T[]): Returns an array of the object's enumerable property values.