Store Data into Browser local storage and sessionStorage.
1.setItem(key, value) – Add key and value to sessionStorage or localStorage.
localStorage.setItem("Order_id","12345");
or
sessionStorage.setItem("first_name","Vikas");
2. getItem(key) – This is how you get items from sessionStorage or localStorage.
localStorage.getItem("Order_id");
or
sessionStorage.getItem("first_name");
3.removeItem(key) – remove the key with its value from sessionStorage or localStorage.
localStorage.removeItem("Order_id");
or
sessionStorage.removeItem("first_name");
4. clear() – Clear all from sessionStorage or localStorage.
localStorage.clear();
or
sessionStorage.clear();
5. key(index) – Passed a number to retrieve the key of a sessionStorage or localStorage.
localStorage.key(0);
localStorage.key(1);
or
sessionStorage.key(0);
sessionStorage.key(1);
6. length – The number of stored items.
localStorage.length;
or
sessionStorage.length;
No comments:
Post a Comment