This article mainly introduces javascript data storage common functions summary related information, friends in need can refer to
common functions of data storage
Save arraynon-duplicate values
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; }
Delete elements in the array
Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } };
Save objectsto localStorage
function setObjectStorage(itemname,myobj){ localStorage.setItem(itemname, JSON.stringify(myobj)); } function getObjectStorage(itemname){ return JSON.parse(localStorage.getItem(itemname)); }
The above is the detailed content of Summary of common functions for data storage in JavaScript. For more information, please follow other related articles on the PHP Chinese website!