I would like to iterate a TypeScript enum object and get each enumerated symbol name, for example: enum myEnum { entry1, entry2 }
for (var entry in myEnum) { // use entry's name here, e.g., "entry1" }
Use a list comprehension to get a list of all enum values, e.g. values = [member. value for member in Sizes] . On each iteration, access the value attribute on the enum member to get a list of all of the enum's values.
To get all enum values as an array, pass the enum to the Object. values() method, e.g. const values = Object. values(StringEnum) . The Object.
SOLUTION: int enumValue = 2; // The value for which you want to get string string enumName = Enum. GetName(typeof(EnumDisplayStatus), enumValue);
Though the answer is already provided, Almost no one pointed to the docs
Here's a snippet
enum Enum { A } let nameOfA = Enum[Enum.A]; // "A"
Keep in mind that string enum members do not get a reverse mapping generated at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With