Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
For a regular string enum, use Object.values(MyEnum) to get an array of its values. For a numeric enum, filter the result because TypeScript adds reverse mappings that make the unfiltered array contain both numbers and member names.
Convert a string enum to an array of values
String enums do not have reverse mappings, so Object.values() returns the declared string values:
enum Direction {
Up = "UP",
Down = "DOWN",
Left = "LEFT",
Right = "RIGHT",
}
const directionValues = Object.values(Direction);
// ["UP", "DOWN", "LEFT", "RIGHT"]
This is the concise option when the array should contain the enum’s string values.
Recommended Free Tools
Convert a numeric enum to an array
Numeric enums have a forward mapping from member names to numbers and a reverse mapping from numbers to member names. As a result, Object.values() on a numeric enum contains both kinds of entries. Filter by type to keep only the numeric values:
#1 Best Overall
enum Status {
Pending,
Active,
Complete,
}
const statusValues = Object.values(Status).filter(
(value): value is Status => typeof value === "number",
);
// [0, 1, 2]
The type predicate value is Status tells TypeScript that the filtered results are enum values. Explicit or sparse numeric assignments remain sparse: this returns the values declared by the enum, not every number between zero and the largest value.
Get enum member names instead
If you need the declared names of a numeric enum rather than its values, filter out the numeric keys produced by reverse mappings:
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
const colorNames = Object.keys(Color).filter(
(key) => Number.isNaN(Number(key)),
);
For example, given enum Color { Red, Green, Blue }, this produces ["Red", "Green", "Blue"]. For a string enum, Object.keys(MyEnum) directly returns its member names because string enums do not have reverse mappings.
Can you convert a const enum?
Not at runtime. A const enum is erased during compilation and its members are inlined, so there is no ordinary enum object to pass to Object.values(). If your code needs runtime iteration, use a regular enum or define a separate runtime array or object.
Use an as const object as an iterable alternative
The TypeScript Handbook notes that an enum may not be necessary when an object with as const is sufficient. The object remains available at runtime, and you can derive a union type from its values:
const Direction = {
Up: "UP",
Down: "DOWN",
Left: "LEFT",
Right: "RIGHT",
} as const;
type Direction = (typeof Direction)[keyof typeof Direction];
const directionValues = Object.values(Direction);
Choose this pattern when a runtime object and a type derived from its values suit the codebase better than enum syntax. See the TypeScript Handbook’s enum documentation for the behavior and alternatives.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →

