JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 241214
  • Score
    100M100P100Q181492F
  • License MIT

Remove undefined properties and empty arrays from an object

Package Exports

  • remove-undefined-objects
  • remove-undefined-objects/package.json

Readme

remove-undefined-objects

Build

Installation

npm install --save remove-undefined-objects

Usage

import removeUndefinedObjects from 'remove-undefined-objects';

console.log(removeUndefinedObjects({key: [], key2: 123}));
// { key2: 123 }

Behavior

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

Options

removeAllFalsy

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 }