Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let mobile_phone = {
- // key: value
- brand: "Apple",
- model: "iPhone 16 Pro",
- rom: 512,
- camera_count : 3,
- color: "Natural Titanium"
- };
- console.log("Mobile Phone Object & Brand")
- console.log(mobile_phone);
- console.log(mobile_phone.brand);
- // Convert object to string
- let mobile_phone_str = JSON.stringify(mobile_phone);
- console.log("Mobile Phone String Version")
- // Print the STRING VERSION
- console.log(mobile_phone_str);
- // Once converted into string, helper functions no longer work.
- console.log(mobile_phone_str.brand);
- // When we send the data somewhere, it's lighter. 5GB could turn into 3GB (Example only)
- // Once text data is RECEIVED by whoever/whatever is receiving, THEN you can convert it back into JSON Object.
- let new_mobile_phone = JSON.parse(mobile_phone_str);
- console.log("Converted Mobile Phone Object from String")
- console.log(new_mobile_phone);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement