- 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 - 集合處理
Underscore.JS 提供了許多易於使用的函式,有助於處理集合。本章將詳細討論這些函式。
Underscore.JS 提供了多種處理集合的方法,如下所示:
| 序號 | 方法及語法 |
|---|---|
| 1 | contains
_.contains(list, value, [fromIndex]) |
| 2 | invoke
_.invoke(list, methodName, *arguments) |
| 3 | pluck
_.pluck(list, propertyName) |
| 4 | max
_.max(list, [iteratee], [context]) |
| 5 | min
_.min(list, [iteratee], [context]) |
| 6 | sortBy
_.sortBy(list, iteratee, [context]) |
| 7 | groupBy
_.groupBy(list, iteratee, [context]) |
| 8 | indexBy
_.indexBy(list, iteratee, [context]) |
| 9 | countBy
_.countBy(list, iteratee, [context]) |
| 10 | shuffle
_.shuffle(list) |
| 11 | sample
_.sample(list, [n]) |
| 12 | toArray
_.toArray(list) |
| 13 | size
_.size(list) |
| 14 | partition
_.partition(list, predicate) |
| 15 | compact
_.compact(list) |
廣告