What is the proper way to loop through literals of an enum in TypeScript?
(I am currently using TypeScript 1.8.1.)
I’ve got the following enum:
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);
}
}
The result displayed is a list
0
1
2
3
Intrusion,
Identification,
AbsenceTest,
Autre
I do want only four iterations in the loop as there are only four elements in the enum. I don’t want to have 0 1 2 and 3 that seem to be index numbers of the enum.