语法:

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

功能:

  • 这个方法类似_.intersection,区别是它接受一个 iteratee 调用每一个arrays的每个值以产生一个值,通过产生的值进行了比较。结果值是从第一数组中选择。iteratee 会传入一个参数:(value)

    参数:

  • [arrays] (…Array): 待检查的数组

  • [iteratee=.identity] (Array|Function|Object|string)_: iteratee(迭代器)调用每个元素

    返回:

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

    例子:

    ```typescript // 给第一个数组和第二个数组中的每个值都调用Math.floor方法,地板函数得[2, 1]和[4, 2],第一个数组数组[2, 1]中无4有2,第一个数组过滤2则得: [2],所以对应原来的就是[3.1] _.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); // => [2.1]

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