Languages
[Edit]
EN

TypeScript - convert enum to array

12 points
Created by:
Root-ssh
178170

In this article, we would like to show how to to get enum names or values in TypeScript.

Quick solution:

Note: runnable example is available here.

 

Reusable code

Edit

The example contains reusable util that helps to extract data from the enums.

Note: runnable example is available here.

Output:

 

Warning: some tools may remove information about enums during source code optimization that makes impossible to extract enum names and values - e.g. preact-cli during production bundle building, browserify, etc. 

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

TypeScript

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join