Created
February 24, 2017 07:10
-
-
Save rjoydip-zz/c989f41fff8c40c60bd6cdbbeb133da0 to your computer and use it in GitHub Desktop.
This function traverse the hole object and checking whether the object value of each layer has a nested object or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isObject(obj){ | |
return (typeof obj === 'object') ? true : false; | |
} | |
function traverse (json, callback) { | |
JSON.parse(json, function (key, value) { | |
if (key !== '') { | |
callback.call(this, key, isObject(value)) | |
} | |
return value | |
}) | |
} | |
traverse('{"a":{"b":{"c":{"d":1}},"e":{"f":2}}}', function (key, value) { | |
console.log(key+ " : " +value) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment