search

Home  >  Q&A  >  body text

javascript - How to use filter to achieve this kind of filtering

let arr1 = ['a','b','c','d'];
let arr2 = [1,4];//通过这个数组过滤掉arr1中索引为1跟4的选项

Can it be achieved using filter

仅有的幸福仅有的幸福2778 days ago695

reply all(4)I'll reply

  • 给我你的怀抱

    给我你的怀抱2017-05-19 10:45:00

    let arr1 = ['a','b','c','d'];
    let arr2 = [1,4];
    arr1.filter((value,index)=>{
        return arr2.indexOf(index) === -1;
    });
    

    reply
    0
  • 怪我咯

    怪我咯2017-05-19 10:45:00

    arr1.filter(function(){
           for(let i = 0 , i < arr2.length, i++){
                  return arr1[arr2[i]] 
           }
    })

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:45:00

    let newArr = arr1.filter((el, index, array) => {
        return arr2.indexOf(index) === -1
    })
    let newArr = arr1.filter((el, index, array) => {
        return !arr2.includes(index)
    })

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-05-19 10:45:00

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

    reply
    0
  • Cancelreply