Skip to content

Instantly share code, notes, and snippets.

@aaronshaf
Last active December 16, 2015 16:19
Show Gist options
  • Save aaronshaf/5462451 to your computer and use it in GitHub Desktop.
Save aaronshaf/5462451 to your computer and use it in GitHub Desktop.
Recursively prune key from object
var recursivePrune = function (obj,keyToRemove) {
if(typeof obj === "object" && obj instanceof Array) {
for(x = 0;x < obj.length;x++) {
obj[x] = this.recursivePrune(obj[x],keyToRemove);
}
} else if(typeof obj === "object") {
delete obj[keyToRemove];
Object.getOwnPropertyNames(obj).forEach(function(property) {
obj[property] = recursivePrune(obj[property],keyToRemove);
});
}
return obj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment