Last active
December 28, 2015 08:29
-
-
Save creationix/7471477 to your computer and use it in GitHub Desktop.
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 getKeys(obj) { | |
all = {}; | |
function get(obj) { | |
var keys = Object.keys(obj); | |
for (var i = 0, l= keys.length; i < l; i++) { | |
var key = keys[i]; | |
all[key] = true; | |
var value = obj[key]; | |
if (value instanceof Object) get(value); | |
} | |
} | |
get(obj); | |
return Object.keys(all); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Keep in mind, this needs an implementation of
Object.keys
which can be polyfilled with:Also there is no protection against cycles in the object. That could added at a performance and memory use cost if desired.