1.数组去重(self标识当前数组本身,元素所在对象)
this.seacrhHistory = this.seacrhHistory.filter((item, index, self) => self.indexOf(item) === index)
2.对象数组去重
let options=[
{
value: '选项1',
label: '黄金糕'
}, {
value: '选项2',
label: '双皮奶'
}, {
value: '选项3',
label: '蚵仔煎'
}, {
value: '选项4',
label: '龙须面'
}, {
value: '选项5',
label: '北京烤鸭'
}]
let a =[
{
value: '选项1',
label: '黄金糕'
}, {
value: '选项2',
label: '双皮奶'
},
]
let options1=[
{
value: '选项1',
label: '黄金糕'
}, {
value: '选项2',
label: '双皮奶'
}, {
value: '选项3',
label: '蚵仔煎'
}, {
value: '选项4',
label: '龙须面'
}, {
value: '选项5',
label: '北京烤鸭'
},
{
value: '选项1',
label: '黄金糕'
},
{
value: '选项1',
label: '黄金糕'
}, ]
var c = options.filter(e=> !a.some(c=>e.value == c.value))
var d = options1.filter(e=> e.findIndex(e.value==e.value)==-1)
console.log('c====================c',c)
console.log('s====================c',d)
function un(arr){
var arr1 = []
for(var i = 0;i<arr.length;i++){
if(arr1.indexOf(arr[i])===-1){
arr1.push(arr[i])
}
}
return arr1
}```
let a = ["1", "1", "2", "2", "3"];
// a = a.filter((item, index, self) => self.indexOf(item) == index);
// console.log("a", a);
let b = [];
a.forEach(e => b.indexOf(e) == -1 && b.push(e));