Related questions
How to get names of enum entries?
I would like to iterate a TypeScript an enum type and get each enumerated symbol name, e.g.:
enum myEnum { entry1, entry2 }
for (var entry in myEnum) {
// use entry's name here, e.g., "entry1"
}
How can I loop through enum values for display in radio buttons?
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)
{
…
Check if value exists in enum in TypeScript
I recieve a number type = 3 and have to check if it exists in this enum:
export const MESSAGE_TYPE = {
INFO: 1,
SUCCESS: 2,
WARNING: 3,
ERROR: 4,
};
The best way I found is by getting all Enum Values as an array and using indexOf …