---
title: "separateMany"
description: "Partition an object into several named groups of keys plus an others catch-all, returning a new object for each group in one pass."
canonical_url: "https://core.mhaibaraai.cn/en/docs/helpers/object/separate-many"
---
# separateMany

> Partition an object into several named groups of keys plus an others catch-all, returning a new object for each group in one pass.

## Usage

The `separateMany` function partitions an object into multiple named groups by key sets.

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

const options = { id: 1, name: 'John', email: 'a@b.com', role: 'admin' }
const { a, b, others } = separateMany(options, { a: ['id'], b: ['name'] as const })
// a: { id: 1 }
// b: { name: 'John' }
// others: { email: 'a@b.com', role: 'admin' }
```

## API

### `separateMany(obj, groups)`

Partitions an object into multiple named groups by key sets.

### Parameters

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

**groups** (`M`) *required*: Group mapping, e.g. { a: ['x', 'y'], b: ['z'] }.

### Returns

**returns** (`{ [P in keyof M]: PickByKey<T, M[P][number]> } & { others: OmitByKey<T, M[keyof M][number]> }`): An object containing a sub-object for each group plus others (all keys not captured by any group).

## Changelog

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

---

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


## Sitemap

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