How to check if there is a data in Storage

Asked

Viewed 1,541 times

1

Hello, I am using the library store.js to facilitate and I would like to know how I can do to check if there is a key in Storage.

thank you so much for your attention and good night :D

1 answer

2


store#get() returns the value of the respective key, if it exists, otherwise this value will be Undefined. Then you can use it to check if there is something set to a certain key:

if(store.get('chave')){
   // Existe.
}

I created an example in jsfiddle because snippets here at Stackoverflow do not allow the use of Storage:

Example.

  • 1

    Thanks partner, killed my doubt ! D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.