扫码一下
查看教程更方便
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) |