---
title: "pick"
description: "Return a new object containing only the given keys from the source, a type-safe way to project a subset of an object's fields."
canonical_url: "https://core.mhaibaraai.cn/en/docs/helpers/object/pick"
---
# pick

> Return a new object containing only the given keys from the source, a type-safe way to project a subset of an object's fields.

## Usage

The `pick` function returns a new object containing only the specified keys.

```ts
import { pick } from '@movk/core'

const user = {
  id: 1,
  name: 'John',
  email: 'john@example.com',
  password: 'secret',
  createdAt: '2023-01-01',
  updatedAt: '2023-01-15'
}

const publicInfo = pick(user, ['id', 'name', 'email'])
console.log(publicInfo) // { id: 1, name: 'John', email: 'john@example.com' }

const basicInfo = pick(user, ['id', 'name'])
console.log(basicInfo) // { id: 1, name: 'John' }
```

## API

### `pick<T, K>(obj, keys)`

Returns a new object containing only the specified keys.

### Parameters

**obj** (`T extends AnyObject`) *required*: The source object.

**keys** (`K[]`) *required*: Array of keys to pick.

### Returns

**returns** (`PickByKey<T, K>`): A new object containing only the specified keys.

## Changelog

See commit history for [src/helpers/object/pick.ts](https://github.com/mhaibaraai/movk-core/commits/main/src/helpers/object/pick.ts).

---

- [GitHub](https://github.com/mhaibaraai/movk-core/blob/main/src/helpers/object/pick.ts)


## Sitemap

See the full [sitemap](https://core.mhaibaraai.cn/sitemap.md) for all pages.
