change description for clean json object function to explain more about it's inner workings.

This commit is contained in:
iamsoorena
2017-12-15 20:18:18 +03:30
parent e9327cab11
commit f7123086f7

View File

@ -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}}
*/
```