2020-01-12删除2个数组重复数据分辨出删除的和新增的
2020-01-12 本文已影响0人
太阳照常升起_9c4e
/**
* 权限去除重复的
* 查找删除的
* 查找新增的
*/
let getArrDifference = (arr1, arr2) => {
return arr1.concat(arr2).filter(function(v, i, arr) {
return arr.indexOf(v) === arr.lastIndexOf(v);
});
}
let str1 = [1,2,3];//修改前的权限
let str2 = [3,4,5];//修改后的权限
console.log(getArrDifference(str1,str2))
let newlist = getArrDifference(str1,str2)
console.log(newlist)
let dellist = []
let addlist = []
for(let i in newlist){
if(str1.indexOf(newlist[i]) != -1){//删除
dellist.push(newlist[i])
}
if(str2.indexOf(newlist[i]) != -1){//新增
addlist.push(newlist[i])
}
}
console.log(addlist)
console.log(dellist)