diff --git a/snippets/clean-json-objects.md b/snippets/clean-json-objects.md index 2835b37fd..5268e3911 100644 --- a/snippets/clean-json-objects.md +++ b/snippets/clean-json-objects.md @@ -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}} */ ```