In JavaScript you can use browser’s local storage to store some data. Here is how you can do that…
The syntax to store data in local storage is:
localStorage.setItem(key, value);
E.g.
let fullname = “John Cena”;
localStorage.setItem(“name”, fullname);
You can store any type of data For e.g. text, number, array, object, JSON, etc.
The syntax to retrieve data from local storage is:
localStorage.getItem(key)
E.g.
let dataFromStorage = localStorage.getItem(“fullname”);
console.log(dataFromStorage); //John Cena
While retrieving the data, you need to pass the same key which you used while storing the data.
Remember that this data is will remain in storage even if you refresh the browser.
This data will be retained only in the same browser which you used while storing the data.
The data will be retained until the user deletes the browser’s cache or browser history.
I hope this tutorial helped you understand how to use local storage in Javascript. Let me know your thoughts.
Fully customizable CRM Software for Freelancers and Small Businesses