Created
September 2, 2021 15:53
-
-
Save MateusAndrade/6d187353bafe9afcfc2b3b0bb4ea6a96 to your computer and use it in GitHub Desktop.
Remove recursively all object keys, matching a given name
This file contains hidden or 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
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