pick

import { pick } from "jsr:@ende/collections";

function

function pick<T extends object, K extends keyof T>(obj: Readonly<T>, keys: readonly K[]): Pick<T, K>

Creates a new object by including the specified keys from the provided object.

obj: Readonly<T>

The object to pick keys from.

keys: readonly K[]

The keys to include in the new object.

Returns

A new object with the specified keys from the provided object.

Example: Basic usage

import { pick } from "@ende/collections/pick";
import { assertEquals } from "@ende/assert";

const obj = { a: 5, b: 6, c: 7, d: 8 };
const picked = pick(obj, ["a", "c"]);

assertEquals(picked, { a: 5, c: 7 });

Source