【发布时间】:2017-01-15 07:35:08
【问题描述】:
在 TypeScript 中循环遍历枚举字面量的正确方法是什么?
(我目前使用的是 TypeScript 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);
}
}
显示的结果是一个列表
0
1
2
3
Intrusion,
Identification,
AbsenceTest,
Autre
我只想要循环中的四次迭代,因为枚举中只有四个元素。我不想让 0 1 2 和 3 看起来是枚举的索引号。
【问题讨论】:
-
签出这个enum-for包
标签: javascript arrays typescript enums element