Last active
May 4, 2019 15:50
-
-
Save illvart/60ab2ac13b5f774e7e64b424ffc1ab5a to your computer and use it in GitHub Desktop.
Era Material: JSON - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
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
| var json1 = '{"enable": true, "emotion": ":)"}'; | |
| var json2 = '{"enable": "false", "emotion": ":)"}'; | |
| var obj1 = JSON.parse(json1); | |
| var obj2 = JSON.parse(json2); | |
| console.log(obj1.enable); | |
| console.log(obj1.emotion); | |
| console.log(obj2.enable); | |
| console.log(obj2.emotion); | |
| if (obj1.enable ? true : false) { | |
| console.log("object 1 true" + " " + obj1.emotion); | |
| } else { | |
| console.log("object 1 false" + " " + ":("); | |
| } | |
| if (obj2.enable == "true" ? true : false) { | |
| console.log("object 2 true" + " " + obj2.emotion); | |
| } else { | |
| console.log("object 2 false" + " " + ":("); | |
| } | |
| // output | |
| /* | |
| > true | |
| > ":)" | |
| > "false" | |
| > ":)" | |
| > "object 1 true :)" | |
| > "object 2 false :(" | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment