Created
November 27, 2019 19:15
-
-
Save tomatohammado/49aadd0150c452ff48f45fc4812d7b9a to your computer and use it in GitHub Desktop.
Native Object vs JSON examle
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 testObj = { | |
name: "Hammad", | |
age: 30, | |
favoriteAnime: [ | |
"Cowboy Bebop", | |
"Dragon Ball", | |
"Death Note", | |
"Samurai Champloo" | |
], | |
holla: () => console.log("hollaaaaaaa") | |
}; | |
const jsonTestObj = JSON.stringify(testObj); | |
const parsedJson = JSON.parse(jsonTestObj); | |
/** Testing */ | |
console.log(testObj.name); | |
console.log(testObj.favoriteAnime[0]); | |
console.log(testObj.holla()); | |
console.log(jsonTestObj); | |
console.log(jsonTestObj.name); // doesn't work! | |
console.log(parsedJson.name); | |
console.log(parsedJson.favoriteAnime[0]); | |
console.log(parsedJson.holla()); // doesn't work! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment