+ 24
How to use and destroy web storage in Html5?
2 Réponses
+ 28
To set data:
window.localStorage.setItem(key, value);
To get data:
window.localStorage.getItem(key)
To remove data:
window.localStorage.removeItem(key);
To clear all:
window.localStorage.clear();
To get the length of all the data (keys):
window.localStorage.length
To get a key at position `n`:
window.localStorage.keys(n)
You can use .getItem and .keys to get the first item in the localStorage, like this:
var data = window.localStorage.getItem(window.localStorage.keys(0));