values()
values<
T>(object):T[keyofT][]
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