Last active
August 16, 2019 22:31
-
-
Save djD-REK/28409ce67d988236ceec2d66e8b0b9c3 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)); | |
| // {"name":"Derek","email":"Removed for privacy"} | |
| console.log(JSON.stringify(user, null, "^_^ ")); | |
| // result: { | |
| // ^_^ "id": 101010, | |
| // ^_^ "name": "Derek", | |
| // ^_^ "email": "[email protected]" | |
| // } | |
| console.log(JSON.parse(JSON.stringify(user))); | |
| // result: Object {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