javascript - Typescript : how to loop through enum values for display in radio buttons? -


this question has answer here:

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]))); 

(code in playground)


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -