Skip to content

Instantly share code, notes, and snippets.

@MateusAndrade
Created September 2, 2021 15:53
Show Gist options
  • Save MateusAndrade/6d187353bafe9afcfc2b3b0bb4ea6a96 to your computer and use it in GitHub Desktop.
Save MateusAndrade/6d187353bafe9afcfc2b3b0bb4ea6a96 to your computer and use it in GitHub Desktop.
Remove recursively all object keys, matching a given name
const removeObjectKey = (target, key) => {
Object.keys(target).forEach((objKey) => {
if (typeof target[objKey] === "object") {
return removeObjectKey(target[objKey], key);
}
if (objKey.toLowerCase() === key) {
delete target[objKey];
}
});
return target;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment