Update cleanObj.md

I changed comma operator because it confuses the reader.
This commit is contained in:
Soorena
2017-12-26 14:29:51 +03:30
committed by GitHub
parent e58b397b47
commit 52f7a7dee8

View File

@ -7,13 +7,14 @@ Also if you give it a special key (`childIndicator`) it will search deeply insid
```js
const cleanObj = (obj, keysToKeep = [], childIndicator) => {
return Object.keys(obj).forEach(key => {
Object.keys(obj).forEach(key => {
if (key === childIndicator) {
cleanObj(obj[key], keysToKeep, childIndicator);
} else if (!keysToKeep.includes(key)) {
delete obj[key];
}
 }), obj
 })
return obj
}
/*
const testObj = {a: 1, b: 2, children: {a: 1, b: 2}}