From e642274382dd233efe4a4c816aede6ec9dc0c259 Mon Sep 17 00:00:00 2001 From: iamsoorena Date: Fri, 15 Dec 2017 20:23:23 +0330 Subject: [PATCH] refactoring grammatical problems and assigning better name to keys argument. --- snippets/clean-json-objects.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/snippets/clean-json-objects.md b/snippets/clean-json-objects.md index 5268e3911..5af7b6221 100644 --- a/snippets/clean-json-objects.md +++ b/snippets/clean-json-objects.md @@ -1,14 +1,14 @@ ### Clean Json objects -Use `Object.keys()` method to iter through given json object and deleting keys that are not `include`d in given array. +Use `Object.keys()` method to loop over 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) => { +const cleanObj = (obj, keysToKeep = [], childIndicator) => { Object.keys(obj).forEach(key => { if (key === childIndicator) { - cleanObj(obj[key], keys, childIndicator) - } else if (!keys.includes(key)) { + cleanObj(obj[key], keysToKeep, childIndicator) + } else if (!keysToKeep.includes(key)) { delete obj[key] } })