Skip to content

pick

The pick function returns a new object containing only the specified properties.

Syntax

typescript
pick(obj, keys): object

Parameters

NameTypeDescription
objobjectSource object.
keysstring[]List of properties to select.

Return

TypeDescription
objectReturns a new object containing only the properties specified in keys.

Examples

typescript
pick({ a: 1, b: 2, c: 3 }, ['b']); // { b: 2 }
pick({ x: 10, y: 20 }, ['x', 'y']); // { x: 10, y: 20 }

Notes

  • Does not modify the original object.
  • Useful for extracting subsets of properties.

References

Released under the MIT License.