change description for clean json object function to explain more about it's inner workings.
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
### Clean Json objects
|
### Clean Json objects
|
||||||
|
|
||||||
Clean your json object from unwanted keys, deeply.
|
Use `Object.keys()` method to iter through given json object and deleting keys that are not `include`d in given array.
|
||||||
provide set of `keys` to keep and an indicator for `children` if there is any.
|
also if you give it a special key(`childIndicator`) it will search deeply inside it to apply function to inner objects too.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const cleanObj = (obj, keys = [], childIndicator) => {
|
const cleanObj = (obj, keys = [], childIndicator) => {
|
||||||
@ -14,8 +14,8 @@ const cleanObj = (obj, keys = [], childIndicator) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
dirtyObj = {a: 1, b: 2, children: {a: 1, b: 2}}
|
testObj = {a: 1, b: 2, children: {a: 1, b: 2}}
|
||||||
cleanObj(dirtyObj, ["a"],"children")
|
cleanObj(testObj, ["a"],"children")
|
||||||
console.log(dirtyObj)// { a: 1, children : { a: 1}}
|
console.log(testObj)// { a: 1, children : { a: 1}}
|
||||||
*/
|
*/
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user