# \_.intersectionWith（数组交集）

**语法：**

```javascript
_.intersectionWith([arrays], [comparator])
```

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L7563)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.intersectionwith)

**描述：**

这个方法类似[`_.intersection`](https://lodash.com/docs/4.17.10#intersection)，区别是它接受一个`comparator`调用比较`arrays`中的元素。结果值是从第一数组中选择。comparator 会传入两个参数：*(arrVal, othVal)*。

**开始版本：**&#x34;.0.0

**参数：**

* `array (...Array)`: 待检查的数组。
* `[comparator] (Function)`: comparator（比较器）调用每个元素。

**返回值：**

* `array (Array)`: 返回一个包含所有传入数组交集元素的新数组。

**例子：**

```javascript
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 }]
```
