if(localStorage.getItem("selectcarmsg")){ var arr=JSON.parse(localStorage.getItem("selectcarmsg")); arr.push(selectcarmsg); var jsonstr = [];//json去重 outer: for(var i=0;i<arr.length;i++){ inter: for(var j=i+1;j<arr.length;j++){ if(arr[i].carid==arr[j].carid && arr[i].carposition==arr[j].carposition){ // console.log(arr[i].carid+' '+arr[j].carid); arr.splice(i,1); break inter; } } } localStorage.setItem("selectcarmsg",JSON.stringify(arr));