npm install --save remove-undefined-objectsimport removeUndefinedObjects from 'remove-undefined-objects';
console.log(removeUndefinedObjects({ key: [], key2: 123 }));
// { key2: 123 }Any items with the following value will be removed:
- Empty object,
{} - Empty array,
[] - Undefined,
undefined
The following items will NOT be removed:
- Empty string,
'' - Null,
null
Optional boolean. If provided, null values in arrays will be preserved instead of being removed.
import removeUndefinedObjects from 'remove-undefined-objects';
console.log(removeUndefinedObjects({ key1: [null, undefined], key2: 123 }, { preserveArrayNulls: true }));
// { key1: [null], key2: 123 }Optional boolean.
If provided, the empty string '' and null will be removed as well.
import removeUndefinedObjects from 'remove-undefined-objects';
console.log(removeUndefinedObjects({ key1: null, key2: 123, key3: '' }), { removeAllFalsy: true });
// { key2: 123 }