Advertisement
christanplazaSun

Untitled

Apr 30th, 2025
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let mobile_phone = {
  2.     // key: value
  3.     brand: "Apple",
  4.     model: "iPhone 16 Pro",
  5.     rom: 512,
  6.     camera_count : 3,
  7.     color: "Natural Titanium"
  8. };
  9.  
  10. console.log("Mobile Phone Object & Brand")
  11. console.log(mobile_phone);
  12. console.log(mobile_phone.brand);
  13.  
  14. // Convert object to string
  15. let mobile_phone_str = JSON.stringify(mobile_phone);
  16.  
  17. console.log("Mobile Phone String Version")
  18.  
  19. // Print the STRING VERSION
  20. console.log(mobile_phone_str);
  21.  
  22. // Once converted into string, helper functions no longer work.
  23. console.log(mobile_phone_str.brand);
  24.  
  25. // When we send the data somewhere, it's lighter. 5GB could turn into 3GB (Example only)
  26. // Once text data is RECEIVED by whoever/whatever is receiving, THEN you can convert it back into JSON Object.
  27.  
  28. let new_mobile_phone = JSON.parse(mobile_phone_str);
  29.  
  30. console.log("Converted Mobile Phone Object from String")
  31. console.log(new_mobile_phone);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement