How do I interact with HTML5 local storage objects?
Local storage object is only available in HTML5. The main benefit of this object is that the object persists the values whether you closed the browser.
Also, we can say this is a cookie with no expiration date with more extra benefits and features. Here is the simple syntax of
local storage (we are not covering session storage).
- localStorage.setItem("Author", "Gaurav Kumar Arora");
In above our storage key is 'Author' and subsequent value is 'Gaurav Kumar Arora'
- localStorage.Author= "Gaurav Kumar Arora";
There is one another way (as a C# coder, I like it ), we can add a value of a key. Here we are adding the 'Author' key's value as 'Gaurav Kumar Arora'.
- localStorage.removeItem("Author");
Sometimes we need to operations like removal of a specific key. Here, we are removing the 'Author' key from our local storage.
This is a very simple description of the usage of local storage. I am going to publish a full article on HTML5 (which will cover all the things) .