javascript - Typescript : how to loop through enum values for display in radio buttons? -
this question has answer here:
- how 1 names of typescript enum entries? 10 answers
what proper way loop through litterals of enum in typescript ? (currently using typescrip 1.8.1)
i've got following enum :
export enum motifintervention { intrusion, identification, absencetest, autre } export class interventiondetails implements oninit { constructor( private interservice: interventionservice ) { let i:number = 0; (let motif in motifintervention) { console.log( motif ); } }
the result displayed list
0 1 2 3 intrusion, identification, absencetest, autre
i want 4 iterations in loop there 4 elements in enum, don't want have 0 1 2 , 3 seem index numbers of enum.
two options:
for (let item in motifintervention) { if (isnan(number(item))) { console.log(item); } }
or
object.keys(motifintervention).filter(key => !isnan(number(motifintervention[key])));
Comments
Post a Comment