多种形式数组去重

let shortData=[]; //临时数组
this.dynamicTags //最后所需数组
// 数组去重展示
for (let i = 0; i < shortData.length; i++) {
//循环遍历当前数组  等于-1说明shortDatap[i]在所需数组中不存在
if (this.dynamicTags.indexOf(shortData[i]) == -1) {
this.dynamicTags.push(shortData[i]);
}
}
 
// 包含数组去重
//arr1父数组 arr2子数组
removePointById(arr1, arr2) {
for (let i = 0; i < arr2.length; i++) {
for (let j = 0; j < arr1.length; j++) {
if (arr2[i] == arr1[j]) {
// console.log('输出重复的内容====》',arr1[j],'输出在父数组中的下标=====>', arr1.indexOf(arr1[j]),);
let indexs = arr1.indexOf(arr1[j]);
arr1.splice(indexs, 1);
}
}
}
// console.log('arr1======>',arr1);
return arr1;
},
 

猜你喜欢

转载自www.cnblogs.com/YmWu/p/10899501.html