时间:2021-07-01 10:21:17 帮助过:5人阅读
数据存储的常用函数
存入数组不重复值
- 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;
- }
删除数组中的元素
- 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));
- }
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!