Skip to content

Instantly share code, notes, and snippets.

@HashirHussain
Last active March 28, 2024 07:15
Show Gist options
  • Save HashirHussain/42f01bf29c51cb4765324b0c8c095357 to your computer and use it in GitHub Desktop.
Save HashirHussain/42f01bf29c51cb4765324b0c8c095357 to your computer and use it in GitHub Desktop.
convert undefined to null
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