- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Storing Objects
JavaScript Storage & BOM
JavaScript Storing Objects
JSON.stringifyandJSON.parselet you save objects and arrays in storage.
Storage only holds strings, but most real data is an object.
JSON is the bridge between the two.
Example
Example
javascript
const user = { name: "Ada", age: 36 };
localStorage.setItem("user", JSON.stringify(user));
const saved = JSON.parse(localStorage.getItem("user"));
console.log(saved.name);