@rbxts/jsnatives
Object.values
Returns an array of a given object's own enumerable property values.
Signature
function values<T>(obj: ReadonlyArray<T>): Array<NonNullable<T>>function values<T>(obj: ReadonlySet<T>): Array<true>function values<T>(obj: ReadonlyMap<unknown, T>): Array<NonNullable<T>>function values<T extends object>(obj: T): Array<NonNullable<T[keyof T]>>
Description
The Object.values()
method returns an array containing the values that correspond to all of a given object's own enumerable property names. The return type varies based on the input object type:
- For arrays: returns an array of the values
- For sets: returns an array of
true
values (one for each entry) - For maps: returns an array of the map's values
- For objects: returns an array of the property values
Examples
Object values
const obj = {a: 1, b: 2, c: 3};
print(Object.values(obj)); // [1, 2, 3]
Proxy values
const proxiedObj = new Proxy({}, { ownKeys: () => { return ["a", "b", "c"]; }, get: (target, prop) => { return prop; }});
print(Object.values(proxiedObj)); // ["a", "b", "c"]
Proxy with undefined values
const proxiedWithUndefined = new Proxy({}, { ownKeys: () => { return ["a", "b", "c"]; }, get: (target, prop) => { return prop === "b" ? undefined : prop; }});
print(Object.values(proxiedWithUndefined), Object.keys(proxiedWithUndefined)); // ["a", "c"] ["a", "b", "c"]
Set values
const set = new Set([1, 2, 3]);
print(Object.values(set)); // [true, true, true]
Map values
const map = new Map([["a", 1], ["b", 2], ["c", 3]]);
print(Object.values(map)); // [1, 2, 3]
Array values
const array = [1, 2, 3];
print(Object.values(array)); // [1, 2, 3]