- 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 — uniq 方法
語法
_.uniq(array, [isSorted], [iteratee])
uniq 方法從陣列中返回一個唯一值的陣列。它使用型別安全相等性 (===) 檢查。如果陣列已排序,請傳遞 true 來執行更快的演算法。可傳遞一個迭代器函式來確定專案的唯一性。
示例
var _ = require('underscore');
var list1 = [11, 2, 14, 14, 2, 6]
var list2 = [1, 2, 3, 3, 3, 4, 5]
//Example 1: uniq values
result = _.uniq(list1);
console.log(result)
//Example 2: uniq values of an sorted array
result = _.uniq(list2, true);
console.log(result)
將上述程式儲存在 tester.js 中。執行以下命令來執行此程式。
命令
\>node tester.js
輸出
[ 11, 2, 14, 6 ] [ 1, 2, 3, 4, 5 ]
underscorejs_processing_array.htm
廣告