---
title: "separate"
description: "Split an object into picked and omitted parts by the given keys, returning both in one call, ideal for separating sensitive fields."
canonical_url: "https://core.mhaibaraai.cn/en/docs/helpers/object/separate"
---
# separate

> Split an object into picked and omitted parts by the given keys, returning both in one call, ideal for separating sensitive fields.

## Usage

The `separate` function splits an object into two parts by the specified keys.

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

const user = {
  id: 1,
  name: 'John',
  email: 'john@example.com',
  password: 'secret',
  role: 'admin'
}

const { picked, omitted } = separate(user, ['id', 'name'])
console.log(picked) // { id: 1, name: 'John' }
console.log(omitted) // { email: 'john@example.com', password: 'secret', role: 'admin' }

// Separate sensitive information
const { picked: publicData, omitted: privateData } = separate(user, ['id', 'name', 'email'])
```

## API

### `separate(obj, keys)`

Splits an object into two parts by the specified keys.

### Parameters

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

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

### Returns

**returns** (`{ picked: PickByKey<T, K>, omitted: OmitByKey<T, K> }`): An object containing both picked and omitted sub-objects.

## Changelog

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

---

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


## Sitemap

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