diff --git a/snippets/cleanObj.md b/snippets/cleanObj.md index 2b74d6743..099b607ab 100644 --- a/snippets/cleanObj.md +++ b/snippets/cleanObj.md @@ -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}}