Object
pick

🎯 Creates an object composed of the picked object properties.

The source object can be a `Plain Object` or an `Array`.

Syntax

import { pick } from '@opentf/std';
 
pick<T extends object, K extends keyof T>(
  obj: T,
  ...paths: (string | unknown[])[]
): Partial<T>;

Parameters

  • obj: The source object or array.
  • ...paths: The property paths to pick.

Returns

A new object or array with only the picked properties.

Examples

pick({ a: 1, b: 2 }, 'a') //=> { a: 1 }
 
pick([1, 2, 3], '0') //=> [1]
 
pick({ a: { b: { c: 1 }, d: null, e: [10, 20, 30] } }, 'a.b', ['a', 'e', '2'])
//=> {
//   a: { b: { c: 1 } },
//   e: [30] 
// }

Related

Try