pick
@guoba-ai/utils / object / pick
Function: pick()
function pick<T, K>(obj, keys): Pick<T, K>;Defined in: object.ts:106
Create a new object with only the specified keys.
Parameters
obj
T
The source object
keys
K[]
Keys to pick
Returns
Pick<T, K>
A new object with only the specified keys
Example
pick({ a: 1, b: 2, c: 3 }, ['a', 'c']) // { a: 1, c: 3 }
pick({ a: 1, b: 2 }, []) // {}
const nested = { value: 1 }
pick({ nested, hidden: true }, ['nested']).nested === nested // trueWarning
This is a shallow copy. Nested objects are shared with the source object.