deep-omit
v1.0.1
Published
Recursively omit the specified key or keys from an object
Downloads
64
Maintainers
Readme
deep-omit
Recursively omit the specified key or keys from an object.
Installation
Install with npm
npm install deep-omit
Usage
const omit = require("deep-omit")
omit a value:
const obj = { one: 1, two: 2 }
omit(obj, 'one')
// or
omit(obj, ['one'])
// result: { two: 2 }
omit a nested value:
const obj = { one: 1, nested: { two: 2 } }
omit(obj, 'nested.two')
// result: { one: 1, nested: {} }
omit multiple values:
const obj = { one: 1, two: 2, nested: { two: 2 } }
omit(obj, ['one', 'two'])
// result: { nested: { two: 2 } }
// note that it didn't delete 'nested.two' how any other 'omit' library doing
works with array as well:
const arr = ['one', 'two', 'three']
omit(arr, 1)
// or
omit(arr, ['1'])
// result: ['one', 'three']
and with nested arrays:
const arr = ['one', 'two', ['three']]
omit(arr, ['2.0'])
// result: ['one', 'two', []]
Running tests
npm i && npm test