compact
Removes all entries with falsy values (false, null, undefined, 0, "", NaN) from an object.
Own keys that are prototype-polluting strings (__proto__, constructor, prototype) are
silently skipped.
Available since v2.0.0
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
obj | T | The source object |
Returns
Section titled “Returns”Partial<T> — A new object containing only entries with truthy values
Examples
Section titled “Examples”Remove falsy values from object
Section titled “Remove falsy values from object”Removes all entries with falsy values (false, null, undefined, 0, "", NaN).
Clean up API response
Section titled “Clean up API response”Useful to strip empty or missing fields before sending data.
