To check if a key exists in HTML local storage by using JavaScript, you can use the getItem() method of the localStorage object.

The getItem() method returns the current value associated with the given key. If the key does not exist, getItem() returns null which is sufficient to verify if the key exists or not:

if (localStorage.getItem('email') !== null) {
    console.log(`Email address exists`);
} else {
    console.log(`Email address not found`);
}

Take a look at this article to learn more about HTML web storage API and how to use localStorage and sessionStorage objects to store data in the user's browser.

✌️ Like this article? Follow me on Twitter and LinkedIn. You can also subscribe to RSS Feed.