---
title: "separateMany"
description: "将对象按多分组键集合进行分离"
seo_title: "separateMany"
seo_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/docs/helpers/object/separate-many"
---
# separateMany

> 将对象按多分组键集合进行分离

## 用法

`separateMany` 函数用于将对象按多分组键集合进行分离。

```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)`

将对象按多分组键集合进行分离。

### 参数

**obj** (`T`) *required*: 源对象。

**groups** (`M`) *required*: 分组映射,如 { a: \['x', 'y'\], b: \['z'\] }。

### 返回值

**返回值** (`{ [P in keyof M]: PickByKey<T, M[P][number]> } & { others: OmitByKey<T, M[keyof M][number]> }`): 包含每个分组的子对象以及 others(其余未被分组捕获的键)。

## Changelog

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


## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
