#getitem(key) Gets the value of a parameter and returns the value associated with the key. The given key exists in the list associated with this object.
if(localStorage.getItem("user")===null) { //... }
But if the key does not exist in the list then it passes null value using the code given below
You can also follow the procedure given below -
if("user" in localStorage){ alert('yes'); } else { alert('no'); }
The above is the detailed content of Check if a key exists in HTML5 local storage. For more information, please follow other related articles on the PHP Chinese website!