Skip to main content

values()

values<T>(object): T[keyof T][]

values(object): []

values(object): unknown[]

Creates an array of the own enumerable property values of an object.

DEPRECATED

Use Object.values() directly instead.


Type Parameters​

T: T extends object​

The type of the object.


Parameters​

Overload 1:

object: T​

The object to query.

Overload 2:

object: null | undefined​

The object to query.

Overload 3:

object: unknown​

The object to query.


Returns: T[keyof T][]​

An array of property values.


See Also​


Since​

2.0.0


Also known as​

values (Lodash, es-toolkit, Remeda, Radashi, Ramda, Effect) · ❌ (Modern Dash, Antfu)


Example​

const obj = { a: 1, b: 2, c: 3 };

// ❌ Deprecated approach
const objValues = values(obj);
console.log(objValues); // [1, 2, 3]

// βœ… Recommended approach
const nativeValues = Object.values(obj);
console.log(nativeValues); // [1, 2, 3]

How it works?​

Creates an array of own enumerable property values. Deprecated: Use Object.values() directly (ES2017).

Native Equivalent​

// ❌ values(obj)
// βœ… Object.values(obj)

Use Cases​

Get all values πŸ“Œβ€‹

Extract all property values from object.

Object.values({ a: 1, b: 2, c: 3 });
// [1, 2, 3]

Sum numeric values​

Calculate total of object values.

const prices = { apple: 1.5, banana: 0.75, orange: 2 };
const total = Object.values(prices).reduce((a, b) => a + b, 0);
// 4.25