Home > sculp-js > arrayEachAsync
arrayEachAsync() function
异步遍历数组,返回 false 中断遍历
Signature:
typescript
export declare function arrayEachAsync<V>(array: ArrayLike<V>, iterator: (val: V, idx: number) => Promise<any> | any, reverse?: boolean): Promise<void>;Parameters
Parameter | Type | Description |
|---|---|---|
array |
| 数组 |
iterator | (val: V, idx: number) => | 支持Promise类型的回调函数 |
reverse | boolean | (Optional) 是否反向遍历 |
Returns:
Promise<void>
Example
使用范例如下: const start = async () => { await arrayEachAsync(result, async (item) => { await request(item); count++; }) console.log('发送次数', count); }
for await...of 使用范例如下 const loadImages = async (images) => { for await (const item of images) { await request(item); count++; } }