天天看點

将兩個數組中重複的資料保留

将兩個數組中重複的資料保留

描述: 在右側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

繼續閱讀