且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从另一个数组的所有元素中过滤一个数组

更新时间:2022-11-18 22:43:36

您可以使用 filter() 函数的 this 参数来避免存储过滤器数组在一个全局变量中.

You can use the this parameter of the filter() function to avoid to store your filter array in a global variable.

var filtered = [1, 2, 3, 4].filter(
    function(e) {
      return this.indexOf(e) < 0;
    },
    [2, 4]
);
console.log(filtered);