Last active
March 28, 2024 07:15
-
-
Save HashirHussain/42f01bf29c51cb4765324b0c8c095357 to your computer and use it in GitHub Desktop.
convert undefined to null
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
function undefinedToNull(arg) { | |
if (arg == undefined || arg == null) return null | |
if (Array.isArray(arg)) return arg.map(undefinedToNull) | |
if (arg.constructor === Object) { | |
Object.keys(arg).forEach(key => { | |
arg[key] = undefinedToNull(arg[key]) | |
}) | |
} | |
return arg | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment