API
@agape/util

pick Function

Creates a new object by picking only the specified properties from the original object.

API

function pick<T extends object, K extends string | number | symbol>(  instance: T,  keys: K[]): Pick<TK>

pick

Pick<T, K>

Creates a new object by picking only the specified properties from the original object.

@paraminstance:  T
The source object to pick properties from
@paramkeys:  K[]
Array of property names to include in the result
@returnsPick<T, K>

Description

Creates a new object by picking only the specified properties from the original object.

This function returns a new object that contains only the properties specified in the keys parameter from the original object.

Usage

Pick a single property

const user = { id: 1, name: 'John', email: '[email protected]', password: 'secret' };

// Pick single property
const nameOnly = pick(user, ['name']);

Pick multiple properties

const user = { id: 1, name: 'John', email: '[email protected]', password: 'secret' };

const publicInfo = pick(user, ['id', 'name', 'email']);
// Result: { id: 1, name: 'John', email: '[email protected]' }