Skip to content

Function: stripUndefinedValuesFromObject()

ts
function stripUndefinedValuesFromObject<T>(
  obj: T,
): ObjectStrippedOfUndefinedValues<T>;

Removes all properties with undefined values from an object. This is useful for cleaning up objects before passing them to APIs or components that should not receive undefined values.

Type Parameters

Type ParameterDescription
T extends Record<string, any>The type of the input object

Parameters

ParameterTypeDescription
objTThe object to process

Returns

ObjectStrippedOfUndefinedValues<T>

A new object with all undefined values removed

Example

typescript
const input = { a: 1, b: undefined, c: "hello", d: undefined };
const result = stripUndefinedValuesFromObject(input);
// result: { a: 1, c: 'hello' }