remove-anything
v2.0.2
Published
Remove any prop (eg. `undefined`) from an object
Downloads
2,669
Maintainers
Readme
Remove Anything ✂️
npm i remove-anything
Removes props (eg. undefined) from an object
An optimised way to remove any prop (eg. undefined
, empty objects, ...) from an object. A small and simple integration.
Usage
import { removeProp } from 'remove-anything'
const payload = { a: 1, b: undefined }
const noUndefined = removeProp(payload, undefined)
noUndefined // { a: 1 }
const payload = { a: 1, b: undefined }
const no1 = removeProp(payload, 1)
no1 // { b: undefined }
Remove multiple props
You can keep on passing parameters to remove additional props
const payload = { a: 1, b: undefined }
removeProp(payload, 1, undefined)
// returns
// {}
Remove Empty Objects and Arrays
const payload = { a: 1, b: undefined, c: {}, d: [] }
removeProps(payload, {}, [])
// returns
// { a: 1, b: undefined }