Last active
February 24, 2017 08:26
-
-
Save rjoydip-zz/7ad54cdec7ad6ef3a2297ee715a43eab to your computer and use it in GitHub Desktop.
This is my own object traversal function and returning whether a object has a nested object or not (using recursion)
This file contains hidden or 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 traverse (obj, callback) { | |
Object.keys(obj).forEach(function(value){ | |
if (typeof obj[value] == 'object') { | |
traverse(obj[value],callback); | |
callback(value,true); | |
} | |
else { | |
callback(value,false) | |
} | |
}); | |
} | |
var myObj = { | |
id: 1, | |
name: 'joy', | |
address : { | |
street : 'abc', | |
lane: { | |
a : 1 | |
} | |
} | |
}; | |
traverse(myObj, function (value,status) { | |
console.log(value+ " : " +status); | |
}) | |
console.log(myObj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment