Skip to content

Function: objWithoutKeys() ​

objWithoutKeys(input, keys, output?): Record<PropertyKey, unknown>

Defined in: packages/core/src/obj/objWithoutKeys.ts:36

Creates a new object excluding specific properties

Parameters ​

input ​

unknown

keys ​

string[]

property names to exclude

output? ​

Record<PropertyKey, unknown>

(optional) to delete unwanted props from the original input use it here. Default: a copy of the input object

Returns ​

Record<PropertyKey, unknown>

Examples ​

Create a new object excluding specific properties ​

javascript
import { objWithoutKeys } from '@superutils/core'

const result = objWithoutKeys({ a: 1, b: '2', c: false }, ['b', 'c'])
console.log(result) // { a: 1 }

Copy one object's properties to another while ignoring specific properties ​

javascript
import { objWithoutKeys } from '@superutils/core'

const source = { a: 1, b: '2', c: false }
const dest = { d: 4, e: 5 }
const result = objWithoutKeys(source, ['b', 'c'], dest)
console.log(result) // { d: 4, e: 5, a: 1 }
console.log(result === dest) // true