Last active
December 16, 2015 16:19
-
-
Save aaronshaf/5462451 to your computer and use it in GitHub Desktop.
Recursively prune key from object
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
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