pick
The pick
function creates a new object by selecting specified keys from
the original object. It takes an object and an array of keys to include,
returning a new object that contains only the properties specified in the
keys array. This is useful for extracting relevant data from an object while
ignoring other properties.
- @param
object
- The original object from which keys will be selected. - @param
keys
- An array of keys (property names) to include in the new object. - @returns A new object that contains only the properties of
object
specified in thekeys
array.
Example
pick({ a: 1, b: 2, c: 3 }, ['a', 'c']) // { a: 1, c: 3 }