Created
November 6, 2014 18:13
-
-
Save alexanderGugel/aceb9d83c3769d113853 to your computer and use it in GitHub Desktop.
Recursively extract keys from nested object
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
var object = { | |
hello: 'world', | |
hallo: { | |
german: 'welt', | |
test: { | |
test: true, | |
test: false | |
} | |
} | |
}; | |
var keys = function (object) { | |
var keys = {}; | |
var recurse = function (object) { | |
if (typeof object !== 'object') return; | |
for (var key in object) { | |
keys[key] = true; | |
recurse(object[key]); | |
} | |
}; | |
recurse(object); | |
return Object.keys(keys); | |
}; | |
console.log(keys(object)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment