
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Checking if a key exists in HTML5 Local Storage
The getitem(key) takes value for one parameter and returns the value associated with the key. The given key is present in the list associated with the object.
if(localStorage.getItem("user")===null) { //... }
But if the key is not present in the list then it passes null value by using the below-given code
You can also follow the below-given procedure −
if("user" in localStorage){ alert('yes'); } else { alert('no'); }
- Related Articles
- Checking if a key exists in a JavaScript object
- Difference between Session Storage and Local Storage in HTML5
- How to store a name permanently using HTML5 Local Storage?
- Checking if element exists with Python Selenium.
- Check if a particular key exists in Java LinkedHashMap
- Check if a given key exists in Java HashMap
- Storing Credentials in Local Storage
- Thread-local storage (TLS)
- How to check if a key exists in a Python dictionary?
- How to check if a key exists in a map in Golang?
- Difference between Local Storage, Session Storage, and Cookies in JavaScript
- Java Program to check if a particular key exists in TreeMap
- How to Check if a Key Exists in the Hashtable in C#?
- Trick to store credentials in local storage
- Retrieve element from local storage in JavaScript?

Advertisements