Topic: Storage management function addition request

dreamcc free asked 1 year ago

Expected behavior

Just want to judge whether the specified cache name exists in the cache and return a Boolean value


Hope to increase



var res = Storage.has('StorageName');
if(res == true){
    // ......
    // ......

Actual behavior。 No such function. 没有这样的功能

Grzegorz Bujański staff answered 1 year ago

We don't have such a method, but you can easily use the get method to do this:

Storage.set('date', new Date());
Storage.set('example', '');

console.log(Boolean(Storage.get('date'))); // -> true
console.log(Boolean(Storage.get('example'))); // -> false
console.log(Boolean(Storage.get('example2'))); // -> false

In some cases, you may want to store false in storage. In this case, it is better to create an additional method that will check it:

Storage.set('false', false);

const has = (name) => {
  const storageValue = Storage.get(name);
  return storageValue === false ? true : Boolean(storageValue);

console.log(has('false')); // -> true

dreamcc free answered 1 year ago

All right. It's just that i always feel that lack a little function

In addition, Code version you released ,hope more tests can be conducted

When the caching function is used, an error is reported directly, and no method is found

I have modified the code myself. Please fix this problem in time

Please insert min. 20 characters.


Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.



Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: MDB5 5.0.0
  • Device: PC
  • Browser: Microsoft Edge
  • OS: windows10
  • Provided sample code: No
  • Provided link: No