---
title: "omitUndefined"
description: "从对象中排除值为 undefined 的键"
seo_title: "omitUndefined"
seo_description: "Return a new object with undefined-valued properties removed, a clean way to drop optional fields before serializing or merging."
canonical_url: "https://core.mhaibaraai.cn/docs/helpers/object/omit-undefined"
---
# omitUndefined

> 从对象中排除值为 undefined 的键

## 用法

`omitUndefined` 函数用于从对象中排除值为 `undefined` 的键。

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

const data = {
  name: 'John',
  age: undefined,
  city: 'New York',
  country: undefined
}

const cleaned = omitUndefined(data)
console.log(cleaned) // { name: 'John', city: 'New York' }

// 用于 API 请求前清理数据
const requestData = omitUndefined({
  title: 'Post Title',
  content: 'Post content',
  tags: undefined,
  published: true
})
```

## API

### `omitUndefined(obj)`

从对象中排除值为 undefined 的键。

### 参数

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

### 返回值

**返回值** (`Partial<T>`): 排除 undefined 值后的新对象。

## Changelog

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


## Sitemap

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