https://github.com/risen228/deep-omit
Recursively omit the specified key or keys from an object
https://github.com/risen228/deep-omit
deep delete javascript node nodejs object omit remove
Last synced: 9 months ago
JSON representation
Recursively omit the specified key or keys from an object
- Host: GitHub
- URL: https://github.com/risen228/deep-omit
- Owner: risen228
- License: mit
- Created: 2019-05-12T12:39:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-19T13:09:45.000Z (almost 6 years ago)
- Last Synced: 2025-03-11T23:37:12.067Z (10 months ago)
- Topics: deep, delete, javascript, node, nodejs, object, omit, remove
- Language: JavaScript
- Size: 146 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# deep-omit
[](https://www.npmjs.com/package/deep-omit)
[](https://travis-ci.com/risenforces/deep-omit)
Recursively omit the specified key or keys from an object.
## Installation
Install with [npm](https://www.npmjs.com)
```sh
npm install deep-omit
```
## Usage
```js
const omit = require("deep-omit")
```
**omit a value:**
```js
const obj = { one: 1, two: 2 }
omit(obj, 'one')
// or
omit(obj, ['one'])
// result: { two: 2 }
```
**omit a nested value:**
```js
const obj = { one: 1, nested: { two: 2 } }
omit(obj, 'nested.two')
// result: { one: 1, nested: {} }
```
**omit multiple values:**
```js
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:**
```js
const arr = ['one', 'two', 'three']
omit(arr, 1)
// or
omit(arr, ['1'])
// result: ['one', 'three']
```
**and with nested arrays:**
```js
const arr = ['one', 'two', ['three']]
omit(arr, ['2.0'])
// result: ['one', 'two', []]
```
## Running tests
```sh
npm i && npm test
```