欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript 數(shù)據(jù)存儲的常用函數(shù)總結(jié)

 更新時間:2017年06月01日 11:24:35   作者:lilugirl  
這篇文章主要介紹了javascript 數(shù)據(jù)存儲的常用函數(shù)總結(jié)的相關(guān)資料,需要的朋友可以參考下

 數(shù)據(jù)存儲的常用函數(shù)

存入數(shù)組不重復值

function pushtoArray(myarr,mydata){

   if(myarr.length==0){

     myarr.push(mydata);
   }else{
     var oktopush=true;
     for(var ele in myarr){


       if(myarr[ele]==mydata){
         oktopush=false;



       }
     }

     if(oktopush){
       myarr.push(mydata);
     }


   }

   return myarr;

 }

刪除數(shù)組中的元素

Array.prototype.remove = function(val) {
     var index = this.indexOf(val);
     if (index > -1) {
       this.splice(index, 1);
     }
   };

存入對象到localStorage

function setObjectStorage(itemname,myobj){
   localStorage.setItem(itemname, JSON.stringify(myobj));
 }

 function getObjectStorage(itemname){
   return JSON.parse(localStorage.getItem(itemname));
 }

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

最新評論