javascript - How to use filter to achieve this kind of filtering
仅有的幸福
仅有的幸福 2017-05-19 10:43:00
0
4
692
let arr1 = ['a','b','c','d'];
let arr2 = [1,4];//通过这个数组过滤掉arr1中索引为1跟4的选项

Can it be achieved using filter

仅有的幸福
仅有的幸福

reply all(4)
给我你的怀抱
let arr1 = ['a','b','c','d'];
let arr2 = [1,4];
arr1.filter((value,index)=>{
    return arr2.indexOf(index) === -1;
});
刘奇
arr1.filter(function(){
       for(let i = 0 , i < arr2.length, i++){
              return arr1[arr2[i]] 
       }
})
过去多啦不再A梦
let newArr = arr1.filter((el, index, array) => {
    return arr2.indexOf(index) === -1
})
let newArr = arr1.filter((el, index, array) => {
    return !arr2.includes(index)
})
给我你的怀抱

arr1 = arr1.filter((e,i) => arr2.indexOf(i)===-1)
The subscript starts from 0

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template