我想知道如何迭代TypeScript枚举和每个枚举的符号名称.
例如,
enum myEnum { entry1, entry2 }
for (var entry in myEnum) {
// use entry's name here, e.g., "entry1"
}
Run Code Online (Sandbox Code Playgroud) 在Typescript中循环枚举枚举的正确方法是什么?(目前使用的是typescrip 1.8.1)
我有以下枚举:
export enum MotifIntervention {
Intrusion,
Identification,
AbsenceTest,
Autre
}
export class InterventionDetails implements OnInit
{
constructor( private interService: InterventionService )
{
let i:number = 0;
for (let motif in MotifIntervention) {
console.log( motif );
}
}
Run Code Online (Sandbox Code Playgroud)
显示的结果是一个列表
0
1
2
3
Intrusion,
Identification,
AbsenceTest,
Autre
Run Code Online (Sandbox Code Playgroud)
我确实只想在循环中进行4次迭代,因为枚举中只有4个元素,我不希望0 1 2和3看起来像是枚举的索引号.