How to get names of enum entries?

CalvinDale picture CalvinDale · Aug 7, 2013 · Viewed 387.8k times · Source

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"
}

Answer

shakram02 picture shakram02 · Feb 11, 2017

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.