扫码一下
查看教程更方便
Underscore.JS 有许多易于使用的方法,使得迭代数组变得非常的方便。
Underscore.JS 提供了各种方法来迭代数组,如下所示
| 序号 | 方法 | 语法 |
|---|---|---|
| 1 | first | _.first(array, [n]) |
| 2 | initial | _.initial(array, [n]) |
| 3 | last | _.last(array, [n]) |
| 4 | rest | _.rest(array, [index]) |
| 5 | indexOf | _.indexOf(array, value, [isSorted]) |
| 6 | lastIndexOf | _.lastIndexOf(array, value, [fromIndex]) |
| 7 | sortedIndex | _.sortedIndex(array, value, [iteratee], [context]) |
| 8 | findIndex | _.findIndex(array, predicate, [context]) |
| 9 | findLastIndex | _.findLastIndex(array, predicate, [context]) |
Underscore.JS 有许多易于使用的方法,有助于处理数组。
Underscore.JS 提供了各种方法来处理数组,如下所示
| 序号 | 方法 | 语法 |
|---|---|---|
| 1 | flatten | _.flatten(array, [shallow]) |
| 2 | without | _.without(array, *values) |
| 3 | union | _.union(*arrays) |
| 4 | intersection | _.intersection(*arrays) |
| 5 | difference | _.difference(array, *others) |
| 6 | uniq | _.uniq(array, [isSorted], [iteratee]) |
| 7 | zip | _.zip(*arrays) |
| 8 | unzip | _.unzip(array) |
| 9 | object | _.object(list, [values]) |
| 10 | chunk | _.chunk(array, length) |
| 11 | range | _.range([start], stop, [step]) |