- 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 - union 方法
語法
_.union(*arrays)
union 方法返回傳入陣列的並集,即每個陣列中的唯一值組合而成的陣列。
示例
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: union of list1 and list2
result = _.union(list1, list2);
console.log(result)
//Example 2: union of list1, list2, list3
result = _.union(list1, list2, list3);
console.log(result)
將上述程式儲存到 tester.js 中。執行以下命令來執行此程式。
命令
\>node tester.js
輸出
[ 1, 2, 3, 4, 5, 6, 7 ] [ 1, 2, 3, 4, 5, 6, 7, 8 ]
underscorejs_processing_array.htm
廣告