How to check if a data exists in storage

1

Hello, I'm using the store.js library to make it easier and I'd like to know how I can check to see if a key exists in storage.

Thank you for your attention and good evening: D

    
asked by anonymous 20.06.2016 / 06:56

1 answer

2

store#get() returns the value of its key, if it exists, otherwise that value will be undefined . Then you can use it to check if something is set for a particular key:

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

I've created an example in jsfiddle because the snippets here in StackOverflow do not allow the use of storage :

Example .

    
20.06.2016 / 07:21