Skip to content

Instantly share code, notes, and snippets.

@serby
Created October 4, 2014 20:55
Show Gist options
  • Save serby/8b1af77985499be8eae4 to your computer and use it in GitHub Desktop.
Save serby/8b1af77985499be8eae4 to your computer and use it in GitHub Desktop.
Walk an object and print the javascript accessor for each leaf element
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