Local storage and JSON

Knowledge Videos

Short animated explainers, organised by subject.

Local storage and JSON

localStorage is the browser's notebook for your site. JSON.stringify turns an array or object into text to save, and JSON.parse turns it back.

Try it

Transcript

When you refresh the page, your variables and the tasks on the page disappear. To remember data between visits, the browser has local storage. It is like a small notebook that your website can write in and read later.

Local storage only keeps text. To save an array or an object, turn it into text with J S O N dot stringify. J S O N is a way of writing data as text.

To use the data again, read the text with get item, and turn it back into an array with J S O N dot parse.

Save after every change, and load when the page starts. Now your to-do list remembers its tasks, even after you close the browser.

Remember: local storage is the browser's notebook. J S O N stringify turns data into text to save it, and J S O N parse turns it back.

More in this series