VDL Plugin SDK

pick

Import from @varavel/vdl-plugin-sdk/utils/objects.

function pick<T, K>(obj, keys): Pick<T, K>;

Creates a new object composed of the picked object properties.

This function takes an object and an array of keys, and returns a new object that includes only the properties corresponding to the specified keys.

Type Parameters

Type ParameterDescription
T extends Record<string, any>The type of object.
K extends string | number | symbolThe type of keys in object.

Parameters

ParameterTypeDescription
objTThe object to pick keys from.
keysreadonly K[]An array of keys to be picked from the object.

Returns

Pick<T, K>

A new object with the specified keys picked.

Example

const obj = { a: 1, b: 2, c: 3 };
const result = pick(obj, ['a', 'c']);
// result will be { a: 1, c: 3 }