var uuidArr = ["bbb","vvv","aaa","fff","fff"],flag = true;
var arr1 = [
{"rolename":"aaa"},
{"rolename":"bbb"},
{"rolename":"ccc"},
{"rolename":"ddd"}
];
var arr2 = [
{"rolename":"eee"},
{"rolename":"ccc"},
{"rolename":"aaa"},
{"rolename":"fff"}
];
// 数组查重
for(let i = 0; i < uuidArr.length; i++){
for(let j = i+1; j < uuidArr.length; j++){
if(uuidArr[i] == uuidArr[j]){
flag = false;
break;
}
}
}
if(!flag){
alert("有相同项!");
}else{
alert("都不相同")
}
//数组求差
function getSubtract(unionArr,subsetArr)
{
var new_tmp = new Array();
for(var i=0;i<unionArr.length;i++){
var flag = true;
for(var j=0;j<subsetArr.length;j++){
if(unionArr[i].rolename == subsetArr[j].rolename){
flag = false;
}
}
if(flag){
new_tmp.push(unionArr[i]);
}
}
return new_tmp;
}
var subtract = getSubtract(arr1,arr2);
console.log(subtract);
JS数组查重、数组对象求差集
最新推荐文章于 2024-09-26 15:24:05 发布