local storage is used to store the client data local browser. Unlike cookies, the stored data is never transmitted to a remote web server. The storage is a pair values base. The data is stored by a name-key which is a string and the data value which can be any type of JavaScript supported data types. However, the data is actually stored as a string so to restore the value data type then methods as parseInt()
and parseFloat()
are used.
- To store an item then
localStorage.setItem("nameKey", value);
orlocalStorage["nameKey"] = value;
- To restore the item value then
localStorage.getItem("nameKey");
orlocalStorage["nameKey"];
. - To remove an item then
removeItem("nameKey")
. - To clear the storage then
clear();
- To iterate through all of the name-keys stored by an index then
key(index);
.