Lodash - pullAllBy 方法
语法
_.pullAllBy(array, values, [iteratee=_.identity])
此方法与 _.pullAll 类似,不同之处在于它接受 iteratee,它会针对 array 和 values 的每个元素调用 iteratee 来生成比较它们的标准。 iteratee 使用一个参数调用:(value)。
参数
array (Array) − 要修改的数组。
values (Array) − 要删除的值。
[iteratee=_.identity] (Function) −每个元素调用的迭代器。
输出
(Array) − 返回数组。
示例
var _ = require('lodash'); var listOfNumbers = [{ 'x': 4 }, { 'x': 1 }]; _.pullAllBy(listOfNumbers, [{ 'x': 4 }], 'x'); console.log(listOfNumbers);
将上述程序保存在tester.js中。运行以下命令执行该程序。
命令
\>node tester.js
输出
[ { x: 1 } ]