pick
Creates a new object containing only the specified keys from the source object. Supports dot notation for selecting nested keys.
Import
Section titled “Import”import { pick } from "1o1-utils";import { pick } from "1o1-utils/pick";Signature
Section titled “Signature”function pick<T extends Record<string, unknown>>({ obj, keys }: PickParams<T>): Record<string, unknown>Parameters
Section titled “Parameters”| Name | Type | Required | Description |
|---|---|---|---|
obj | T | Yes | The source object |
keys | (keyof T | string)[] | Yes | Keys to include (supports dot notation for nested keys) |
Returns
Section titled “Returns”Record<string, unknown> — A new object with only the specified keys.
Examples
Section titled “Examples”pick({ obj: { a: 1, b: 2, c: 3 }, keys: ["a", "c"] });// => { a: 1, c: 3 }
// Nested keys with dot notationpick({ obj: { a: 1, b: { x: 10, y: 20 } }, keys: ["a", "b.x"] });// => { a: 1, b: { x: 10 } }Edge Cases
Section titled “Edge Cases”- Throws if
objis not an object. - Throws if
keysis not an array. - Supports nested key selection via dot notation.
- Missing keys are silently skipped.
Also known as
Section titled “Also known as”select keys, extract properties, subset object, pluck
Prompt suggestion
Section titled “Prompt suggestion”I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use pick to extract only needed fields from an API response