Appearance
super-tools-lib - v1.74.0 / Modules / loop
Module: loop
Table of contents
Collection Functions
Other Functions
Collection Functions
forEach
▸ forEach<T>(data, iteratee): void
循环数组/对象
Since
1.0.0
Example
ts
const arr = [1, 2, 3, 4, 5];
_.forEach(arr, (value, index) => {
// return false 终止循环
});
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
data | Record<string, T> | T[] | 用来迭代的数据 |
iteratee | (item: T, key?: string | number) => boolean | void | 每次迭代调用的函数 |
Returns
void
Other Functions
_arrayEach
▸ _arrayEach(array, iteratee): void
Parameters
| Name | Type |
|---|---|
array | any |
iteratee | any |
Returns
void
_arrayFilter
▸ _arrayFilter(array, iteratee): any[]
Parameters
| Name | Type |
|---|---|
array | any |
iteratee | any |
Returns
any[]
_objectEach
▸ _objectEach(obj, iteratee): void
Parameters
| Name | Type |
|---|---|
obj | any |
iteratee | any |
Returns
void
_objectFilter
▸ _objectFilter(obj, iteratee): any[]
Parameters
| Name | Type |
|---|---|
obj | any |
iteratee | any |
Returns
any[]
filter
▸ filter<T>(data, iteratee): T[]
过滤数组/对象
Since
1.62.0
Example
ts
import { filter } from 'super-tools-lib'
filter([1,2,3], (i) => i <= 2 ) // [1,2]
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
data | Record<string, T> | T[] | 用来迭代的数据 |
iteratee | (item: T, key?: string | number) => boolean | 每次迭代调用的函数 |
Returns
T[]
返回过滤后数组