Categories
JavaScript Answers

How to convert TypeScript enum to an object array?

Spread the love

To convert TypeScript enum to an object array, we use the Object.values method.

For instance, we write

enum Colors {
  WHITE = 0,
  BLACK = 1,
  BLUE = 3,
}

const colorValueArray = Object.values(Colors);

to call Object.values with the Colors enum to return the values in the enum as an array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.