---
title: "omit"
description: "从对象中排除指定的键，返回新对象"
seo_title: "omit"
seo_description: "Return a new object that excludes the given keys, leaving the source untouched, useful for stripping fields before output."
canonical_url: "https://core.mhaibaraai.cn/docs/helpers/object/omit"
---
# omit

> 从对象中排除指定的键，返回新对象

## 用法

`omit` 函数用于从对象中排除指定的键，返回新对象。

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

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

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

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

## API

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

从对象中排除指定的键，返回新对象。

### 参数

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

**keys** (`K[]`) *required*: 要排除的键数组。

### 返回值

**返回值** (`OmitByKey<T, K>`): 排除指定键后的新对象。

## Changelog

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


## Sitemap

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