Created
October 4, 2014 20:55
-
-
Save serby/8b1af77985499be8eae4 to your computer and use it in GitHub Desktop.
Walk an object and print the javascript accessor for each leaf element
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 walk(parent, obj) { | |
if (Array.isArray(obj)) { | |
obj.forEach(function (a, i) { | |
walk(parent + '[' + i + ']', a) | |
}) | |
} else if (obj !== null && typeof obj === 'object') { | |
Object.keys(obj).forEach(function (key) { | |
walk(parent + '.' + key, obj[key]) | |
}) | |
} else { | |
if (parent.indexOf('selectedContexts') !== -1) console.log(parent + ' = ' + obj) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment