Skip to content

intersectionBy

js
_.intersectionBy([arrays], [iteratee=_.identity])

此方法与 _.intersection 类似,不同之处在于它接受 iteratee,调用该方法可生成比较 arrays 的每个元素的标准。结果值的顺序和引用由第一个数组决定。迭代器使用一个参数调用:(value)。

¥This method is like _.intersection except that it accepts iteratee which is invoked for each element of each arrays 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).

新增于

¥Since

4.0.0

参数

¥Arguments

  1. [arrays] (...数组):要检查的数组。

    ¥[arrays] (...Array): The arrays to inspect.

  2. [iteratee=_.identity] (函数):每个元素调用迭代器。

    ¥[iteratee=_.identity] (Function): The iteratee invoked per element.

返回

¥Returns

(数组):返回新的相交值数组。

¥(Array): Returns the new array of intersecting values.

示例

¥Example

js
_.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
// => [2.1]

// The `_.property` iteratee shorthand.
_.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
// => [{ 'x': 1 }]

Lodash v4.17 中文网 - 粤ICP备13048890号