- Underscore.JS 指导手册
- Underscore.JS - 主页
- Underscore.JS - 概览
- Underscore.JS - 环境设置
- Underscore.JS - 遍历集合
- Underscore.JS - 处理集合
- Underscore.JS - 遍历数组
- Underscore.JS - 处理数组
- Underscore.JS - 功能
- Underscore.JS - 映射对象
- Underscore.JS - 更新对象
- Underscore.JS - 比较对象
- Underscore.JS - 实用程序
- Underscore.JS - 链式操作
- Underscore.JS 实用资源
- Underscore.JS - 快速指南
- Underscore.JS - 实用资源
- Underscore.JS - 讨论
Underscore.JS - 交集操作方法
语法
_.intersection(*arrays)
交集操作方法返回传入数组的交集,即每个数组中公共值组成的数组。
示例
var _ = require('underscore');
var list1 = [1, 2, 3, 4, 5, 6]
var list2 = [1, 2, 3, 7]
var list3 = [1, 2, 4, 5, 6, 7, 8]
//Example 1: intersection of list1 and list2
result = _.intersection(list1, list2);
console.log(result)
//Example 2: intersection of list1, list2, list3
result = _.intersection(list1, list2, list3);
console.log(result)
在 tester.js 中保存以上程序。运行以下命令以执行该程序。
命令
\>node tester.js
输出
[ 1, 2, 3 ] [ 1, 2 ]
underscorejs_processing_array.htm
广告