Skip to content

xdash API Reference v0.5.14


xdash API Reference / pick

Function: pick() ​

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

Defined in: src/object.ts:57

Picks properties from an object.

Type Parameters ​

T ​

T

K ​

K extends string | number | symbol

Parameters ​

obj ​

T

object to pick properties from

keys ​

K[]

keys to pick

Returns ​

Pick<T, K>

the object with the picked properties

Example ​

ts
pick({ a: 1, b: 2 }, ['a']) // returns { a: 1 }
pick({ a: 'hello', b: 'world' }, ['a']) // returns { a: 'hello' }
pick({ a: 1, b: 2 }, ['a', 'b']) // returns { a: 1, b: 2 }
pick({ a: 1, b: 2 }, []) // returns {}

Released under the MIT License.