omit

Return a new object that excludes the given keys, leaving the source untouched, useful for stripping fields before output.

Usage

The omit function returns a new object with the specified keys excluded.

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)

Returns a new object with the specified keys excluded.

Parameters

obj
T extends AnyObject required
The source object.
keys
K[] required
Array of keys to exclude.

Returns

returns
OmitByKey<T, K>
A new object with the specified keys removed.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License