记录几种数组去重
1.es6方法简单便捷
uniqueES6 (arr) {
return Array.from(new Set(arr))
},
2.去重并显示重复个数
unique (arr) {
var resultObj = {};
var result = [];
var result2 = [];
for(var i=0; i<arr.length; i++){
if(result.indexOf(arr[i]) == -1){
result.push(arr[i]);
}else{
if(result2.indexOf(arr[i]) == -1){
result2.push(arr[i]);
}
}
}
var obj = {}
arr.forEach((v,k)=>{
if(obj[v]){
obj[v]++;
}else{
obj[v] = 1;
}
});
resultObj.result = result;
resultObj.result2 = result2;
resultObj.obj = obj;
return {resultObj}
},
加一个渲染对象的笔记
let objAll = []
for(let key in curCompdata.obj){
let obj = {}
obj.key=key
obj.value=curCompdata.obj[key]
obj.t=false
objAll.push(obj)
}
this.curCompdata = objAll