If you want to store a small amount of data locally in the mobile device then local storage feature is a good solution. It acts same as the cookies in web application and stores the data as key value pair. The data will persists even after we close the application. It will be removed only after uninstalling the application.
Here is the example to store the date using local storage.
localStorage.firstname = “James”; // Here firstname is the key and James is the value
localStorage.lastname = “Bond”;
Also you can store the data like this
Here is the process to get the data from local storage.
var firstname = localStorage.firstname;
var lastname = localStorage.firstname;
or you can follow this method
var firstname = localStorage.getItem(“firstname”);
var lastname = localStorage.getItem(“lastname”);
So it will return the firstname as James and the lastname as Bond.
If you want the clear the local storage manually, here the the code.
Now if you try to get the firstname or lastname it will return as null.
Remember if you are using local storage for Andoid then do not forget to prefix window before localStorage.
window.localStorage.firstname = “James”;
var firstname = window.localStorage.firstname;