Want to get names of enum entries in Typescript? The code you posted will work; it will print out all the members of the enum, including the values of the enum members. For example, the following code:
1 2 3 4 5 | enum myEnum { bar, foo } for (var enumMember in myEnum) { console.log("enum member: ", enumMember); } |
It Will print the following output:
1 2 3 4 | Enum member: 0 Enum member: 1 Enum member: bar Enum member: foo |
If you instead want only the member names, and not the values, you could do something like this:
1 2 3 4 5 6 | for (var enumMember in myEnum) { var isValueProperty = parseInt(enumMember, 10) >= 0 if (isValueProperty) { console.log("enum member: ", myEnum[enumMember]); } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.