Skip to content

pick

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

It takes an object and an array of keys, and returns a new object with only those keys.

Example

pick({foo: "bar", bar: "foo"}, ["foo"])
// => {foo: "bar"}
pick({foo: "bar", bar: "foo"}, [])
// => {}

Alternatives

Type Parameters

T extends object | ArrayLike<unknown>

K extends string | number | symbol

Parameters

obj

T

The object to take the properties from.

keys

readonly K[]

The keys to select on the object.

Returns

Simplify<Pick<T, K>>

The constructed object.