Skip to content

Instantly share code, notes, and snippets.

@alexanderGugel
Created November 6, 2014 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderGugel/aceb9d83c3769d113853 to your computer and use it in GitHub Desktop.
Save alexanderGugel/aceb9d83c3769d113853 to your computer and use it in GitHub Desktop.
Recursively extract keys from nested object
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