天天看点

将两个数组中重复的数据保留

将两个数组中重复的数据保留

描述: 在右侧val(selectBranchIdList)中不存在的数据删除掉

item为左侧数据

let saveId = [];
for (let index = _this.selectBranchIdList.length - 1; index >= 0 ; index--) {
     _this.teamIds.filter(function(item, second, array){
       if(item.indexOf(_this.selectBranchIdList[index]) !== -1 ){
         saveId.push(item);
       }
       });
    }
           

indexOf返回所查找字符串位置,找不到返回-1

继续阅读