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