Created
April 15, 2014 15:10
-
-
Save petershaw/10740305 to your computer and use it in GitHub Desktop.
underscore.js - keysDeep mixin
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
// returns all keys of a given object in any level depth | |
// ------------------------------------------------------ | |
_.mixin({ | |
keysDeep: function (obj) { | |
var extract = function (obj, result) { | |
_.each(_.keys(obj), function(elm) { | |
if(_.isString(obj[elm])){ | |
result.push(elm); | |
} | |
if(_.isObject(obj[elm])){ | |
result.push(elm); | |
extract(obj[elm], result); | |
} | |
}); | |
return result; | |
} | |
return extract(obj, []); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment