主题
intersectionWith
js
_.intersectionWith([arrays], [comparator])
此方法与 _.intersection
类似,不同之处在于它接受 comparator
,调用该方法可比较 arrays
的元素。结果值的顺序和引用由第一个数组决定。比较器使用两个参数调用:(arrVal, othVal)。
¥This method is like _.intersection
except that it accepts comparator
which is invoked to compare elements of arrays
. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
新增于
¥Since
4.0.0
参数
¥Arguments
[arrays]
(...数组):要检查的数组。¥
[arrays]
(...Array): The arrays to inspect.[comparator]
(函数):每个元素调用的比较器。¥
[comparator]
(Function): The comparator invoked per element.
返回
¥Returns
(数组):返回新的相交值数组。
¥(Array): Returns the new array of intersecting values.
示例
¥Example
js
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
_.intersectionWith(objects, others, _.isEqual);
// => [{ 'x': 1, 'y': 2 }]