Skip to content

Instantly share code, notes, and snippets.

@waaronking
Created August 31, 2017 07:39
Show Gist options
  • Save waaronking/cad5bfa12c1466fdc53242350d707844 to your computer and use it in GitHub Desktop.
Save waaronking/cad5bfa12c1466fdc53242350d707844 to your computer and use it in GitHub Desktop.
Recursively removes a key deep in an object
function removeKeys(obj, key) {
for (const prop in obj) {
if (prop.toString() === key.toString()) {
delete obj[prop];
} else if (typeof obj[prop] === 'object') {
this.removeKeys(obj[prop], key);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment