LocalStorage native encapsulation

var store = {
  isArray:function(param){
     return Array.isArray(param)     
  },
  set:function(keyname,data){
    localStorage.setItem(keyname,JSON.stringify(data));
  },
  get:function(keyname){
      return JSON.parse(localStorage.getItem(keyname));
  },
  add:function(keyname,data){
    var localData = this.get(keyname);
    if(this.isArray(localData.dataObj)){
      localData.dataObj.push(data)
    } else{
      localData.dataObj = data;
    }
    this.set(keyname,localData);
  },
  edit:function(keyname,idParam,data){
    var localData = this.get(keyname);
    if(this.isArray(localData.dataObj)){
      localData.dataObj.forEach(function(v,k){
        if(v.id === idParam){
          localData.dataObj[k] = data    
        }
      });
    } else{
      localData.dataObj = data;
    }
     this.set(keyname,localData);
  },
  delete:function(keyname,idParam){
    var localData = this.get(keyname);
    if(this.isArray(localData.dataObj)){
      localData.dataObj.forEach(function(v,k){
        if(v.id === idParam){
          localData.dataObj.splice(k,1);    
        }
      });
      this.set(keyname,localData);
    }
  }
}

Gods, I was developing a project on mobile, and I encountered a lot of localstorage operations, so I encapsulated a method, which involves adding, deleting, modifying and querying. The dataObj here is a write-to-death array. Please help me to see if there is anything wrong with the encapsulation of this method. Or whether there is a suitable plug-in to encapsulate localStorage.

May.22,2021

is there a problem?


Hello, landlord! Share a frequently used locally stored js library, store.js . It encapsulates ls, ss, and cookie and is compatible with older browsers. Very good. Portal: https://github.com/marcuswest.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3c133-e834.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3c133-e834.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?