Documentation / @andrew_l/toolkit / cleanEmpty
Function: cleanEmpty()
cleanEmpty(
obj):Record<any,any>
Removes properties with empty values from an object.
This function iterates over the object's keys and deletes any property whose value is considered "empty" (e.g., null, undefined, [], {}, '', false).
⚠️ Mutates the original object: The input object is directly modified, and properties are removed from it.
Parameters
obj
Record<any, any>
The object to clean up, where empty fields will be removed.
Returns
Record<any, any>
The cleaned object with empty fields removed.
Examples
ts
const user = { id: 1, name: 'Andrew', roles: [], address: null };
cleanEmpty(user);
console.log(user); // Outputs: { id: 1, name: 'Andrew' }ts
const product = { name: 'Laptop', description: '', price: 1000, tags: [] };
cleanEmpty(product);
console.log(product); // Outputs: { name: 'Laptop', price: 1000 }