主题
differenceBy
js
_.differenceBy(array, [values], [iteratee=_.identity])
此方法与 _.difference
类似,不同之处在于它接受 iteratee
,调用 array
和 values
中的每个元素生成比较标准。结果值的顺序和引用由第一个数组决定。迭代器使用一个参数调用:(value)。
¥This method is like _.difference
except that it accepts iteratee
which is invoked for each element of array
and values
to generate the criterion by which they're compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument: (value).
注意:与 _.pullAllBy
不同,此方法返回一个新数组。
¥Note: Unlike _.pullAllBy
, this method returns a new array.
新增于
¥Since
4.0.0
参数
¥Arguments
array
(数组):要检查的数组。¥
array
(Array): The array to inspect.[values]
(...数组):要排除的值。¥
[values]
(...Array): The values to exclude.[iteratee=_.identity]
(函数):每个元素调用迭代器。¥
[iteratee=_.identity]
(Function): The iteratee invoked per element.
返回
¥Returns
(数组):返回新的过滤值数组。
¥(Array): Returns the new array of filtered values.
示例
¥Example
js
_.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [1.2]
// The `_.property` iteratee shorthand.
_.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
// => [{ 'x': 2 }]