omit

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

用法

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

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

7c832 — refactor!: 重构模块架构,拆分 utils 为专业化模块

Copyright © 2024 - 2026 YiXuan - MIT License