Here are two main ways to convert an Enum to an Array in TypeScript.
- Using the Object.keys() method
- Using the Object.values() method
Enums in TypeScript, unlike interfaces, exist at runtime. They are converted into real objects by the TypeScript compiler.
Converting a Numeric Enum into an Array
To convert a numeric enum into an array, you can use the “Object.values()” method.
enum Days {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
console.log(Object.values(Days));
Output
Converting an Enums key-value pair to an array
To convert TypeScript enum. to an array of key-value pairs, you can use the “Object.entries()” method along with the “filter()” method that removes any pairs where the value isn’t a number.
enum Days {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
const enumPairs: [string, number][] = Object.entries(Days)
.filter(([key, value]) => typeof value === 'number')
.map(([key, value]) => [key, value as number]);
console.log(enumPairs);
Output
Converting a string enum into an array
Here are three ways to convert a string enum to an array in TypeScript.
- Array of Enum’s Keys
- Array of Enum’s Values
- Array of Enum’s Key-Value Pairs
Array of Enum’s Keys
enum Colors {
Red = "RED",
Green = "GREEN",
Blue = "BLUE"
}
const enumKeys: string[] = Object.keys(Colors);
console.log(enumKeys);
Output
Array of Enum’s Values
enum Colors {
Red = "RED",
Green = "GREEN",
Blue = "BLUE"
}
const enumValues: string[] = Object.values(Colors);
console.log(enumValues);
Output
Array of Enum’s Key-Value Pairs
enum Colors {
Red = "RED",
Green = "GREEN",
Blue = "BLUE"
}
const enumPairs: [string, string][] = Object.entries(Colors);
console.log(enumPairs);
Output
That’s it!
Related posts

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.