Home  >  Article  >  Web Front-end  >  Check if a key exists in HTML5 local storage

Check if a key exists in HTML5 local storage

王林
王林forward
2023-09-06 16:53:061130browse

Check if a key exists in HTML5 local storage

#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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete