Sometimes, we want to convert TypeScript enum to object array.
In this article, we’ll look at how to convert TypeScript enum to object array.
How to convert TypeScript enum to object array?
To convert TypeScript enum to object array, we can use the Object.values
method.
For instance, we write
enum Colors {
WHITE = 0,
BLACK = 1,
BLUE = 3,
}
const colorValueArray = Object.values(Colors);
to create the Colors
enum.
Then we call Object.values
with Colors
to return an array of enum values.
Conclusion
To convert TypeScript enum to object array, we can use the Object.values
method.