Lodash - intersection 方法

语法

_.intersection([arrays])

使用 SameValueZero 进行相等性比较,创建一个包含在所有给定数组中的唯一值数组。结果值的顺序和引用由第一个数组决定。

参数

  • [arrays] (...Array) − 要检查的数组。

输出

  • (Array) −返回新的相交值数组。

示例

var _ = require('lodash');
var list = [1, 2, 3, 4, 5, 6];

var result = _.intersection(list,[3,5])
console.log(result);

将上述程序保存在 tester.js 中。运行以下命令执行此程序。

命令

\>node tester.js

输出

[ 3, 5 ]

lodash_array.html