🎯 Creates an object composed of the picked object properties.
Info
The source object can be a `Plain Object` or an `Array`.
Info
When the source object uses Object.create(null), the returned picked object preserves that null prototype, including nested picked containers.
Syntax
TypeScript
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
TypeScript
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] // }