From f7123086f70ce0cb280378e6cebf5b129728a3a3 Mon Sep 17 00:00:00 2001 From: iamsoorena Date: Fri, 15 Dec 2017 20:18:18 +0330 Subject: [PATCH] change description for clean json object function to explain more about it's inner workings. --- snippets/clean-json-objects.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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}} */ ```