Created
August 16, 2019 22:12
-
-
Save djD-REK/bb63f7963aedb3a510d08f960c5c3144 to your computer and use it in GitHub Desktop.
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 user = { | |
id: 101010, | |
name: "Derek", | |
email: "[email protected]" | |
}; | |
function replacer(key, value) { | |
if (typeof value === "number") { | |
return undefined; | |
} | |
if (key === "email") { | |
return "Removed for privacy"; | |
} | |
return value; | |
} | |
console.log(JSON.stringify(user)); | |
// result: {"id":101010,"name":"Derek","email":"[email protected]"} | |
console.log(JSON.stringify(user, replacer)); | |
// result: {"name":"Derek","email":"Removed for privacy"} | |
console.log(JSON.stringify(user, null, "^_^ ")); | |
// result: { | |
// ^_^ "id": 101010, | |
// ^_^ "name": "Derek", | |
// ^_^ "email": "[email protected]" | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment