Check if a key exists in HTML5 local storage

王林
Release: 2023-09-06 16:53:06
forward
1009 people have browsed it

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) {
   //...
}
Copy after login

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');
}
Copy after login

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!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!