Lodash - pullAllWith 方法

语法

_.pullAllWith(array, values, [comparator])

此方法与 _.pullAll 类似,不同之处在于它接受比较器,调用比较器将数组元素与值进行比较。比较器通过两个参数调用:(arrVal, othVal)。

参数

  • array (Array) − 要修改的数组。

  • values (Array) − 要删除的值。

  • [comparator] (Function) −每个元素调用的比较器。

输出

  • (Array) − 返回数组。

示例

var _ = require('lodash');
var listOfNumbers = [{ 'x': 4 }, { 'x': 1 }];

_.pullAllWith(listOfNumbers, [{ 'x': 4 }], _.isEqual);
console.log(listOfNumbers);

将上述程序保存在tester.js中。运行以下命令执行该程序。

命令

\>node tester.js

输出

[ { x: 1 } ]

lodash_array.html