Javascript find index of missing elements of two arrays

前端 未结 4 412
[愿得一人]
[愿得一人] 2021-01-28 18:34

I have the following JavaScript where I have some lists:

var deleteLinks = $(\".remove-button .remove-from-cart\");
deleteLinks.on(\'click\', function(ev){
            


        
4条回答
  •  猫巷女王i
    2021-01-28 19:29

    If you have access to lodash, you can use _.difference to solve this in one line.

    var a = ['a', 'b', 'c'],
      b = ['b'],
      result = [];
    _.difference(a, b).forEach(function(t) {result.push(a.indexOf(t))});
    
    console.log(result);

提交回复
热议问题