- 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
廣告