Skip to content

Instantly share code, notes, and snippets.

@NewEXE
Last active April 12, 2022 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NewEXE/a12d13a15395ee318cef27b401985a7b to your computer and use it in GitHub Desktop.
Save NewEXE/a12d13a15395ee318cef27b401985a7b to your computer and use it in GitHub Desktop.
Typescript Enum to Array
/** For key/value enum: */
export enum CountryEnum {
fra = 'FRANCE',
ukr = 'UKRAINE',
}
// ['FRANCE', 'UKRAINE']
export const CountryList = Object.entries(CountryEnum).map(
([, value]) => value,
);
// ['fra', 'ukr']
export const CountryKeysList = Object.entries(CountryEnum).map(([key]) => key);
/** For values-only enum: */
export enum ExtensionsEnum {
'ext1',
'ext2',
}
// ['ext1', 'ext2']
export const ExtensionsEnum = Object.values(
EnterpriseExtensionsEnum,
).filter((value) => typeof value !== 'number');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment