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