Skip to content

Instantly share code, notes, and snippets.

@petershaw
Created April 15, 2014 15:10
Show Gist options
  • Save petershaw/10740305 to your computer and use it in GitHub Desktop.
Save petershaw/10740305 to your computer and use it in GitHub Desktop.
underscore.js - keysDeep mixin
// 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