Skip to content

removeUndefinedNull

Remove null and undefined values from an object.

Available since v1.0.0

import { removeUndefinedNull } from '@helpers4/object';
removeUndefinedNull<T extends Record<string, string | number | boolean | null | undefined>>(obj: T): Partial<T>
ParameterTypeDescription
objTan object

Partial<T> — A shallow copy of the object without null or undefined values

Returns a shallow copy of the object without null or undefined properties.

removeUndefinedNull({ a: 1, b: null, c: undefined, d: 'ok' })
// => { a: 1, d: 'ok' }

View source on GitHub