<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [com-tools](./com-tools.md) &gt; [safelyIterate](./com-tools.safelyiterate.md)

## safelyIterate() function

safelyIterate(iterable,operation, thisValue) 对 iterable 进行安全的迭代；与 for...of 的区别是：safelyIterate 能保证会迭代过程不会受 operation 中的行为的影响从而迭代每一个元素；

**Signature:**

```typescript
export function safelyIterate<T,ThisValue>(iterable:Iterable<T>,operation:(this:ThisValue,currentValue:T,currentIndex:number,iterable:Iterable<T>)=>any, thisValue?:ThisValue):T[];
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

iterable


</td><td>

Iterable&lt;T&gt;


</td><td>

: Iterable 必选； 可迭代的对象；


</td></tr>
<tr><td>

operation


</td><td>

(this:ThisValue,currentValue:T,currentIndex:number,iterable:Iterable&lt;T&gt;)=&gt;any


</td><td>

: (currentValue,currentIndex,iterable)=<!-- -->&gt;<!-- -->boolean \| undefined 执行的操作， 该函数的返回值表示是否要过滤出该元素


</td></tr>
<tr><td>

thisValue


</td><td>

ThisValue


</td><td>

_(Optional)_ ? : any 可选，默认值是 iterable ；操作 operation 的 this 值


</td></tr>
</tbody></table>
**Returns:**

T\[\]

boolean \| undefined 表示是否要过滤出 currentValue ；

