how to replace empty string with undefined

Solutions on MaxInterview for how to replace empty string with undefined by the best coders in the world

showing results for - "how to replace empty string with undefined"
Mia
14 Mar 2019
1var ab = {
2firstName : undefined,
3lastName : undefined
4}
5
6let newJSON = JSON.stringify(ab, function (key, value) {return (value === "") ? undefined : value});
7
8console.log(JSON.parse(newJSON))