Skip to content

Instantly share code, notes, and snippets.

@NewEXE
Created July 6, 2022 12:42
Show Gist options
  • Save NewEXE/f8b466f8d46d144e76e1c270d237ecd0 to your computer and use it in GitHub Desktop.
Save NewEXE/f8b466f8d46d144e76e1c270d237ecd0 to your computer and use it in GitHub Desktop.
Get enum key by value (Typescript)
export const getEnumKeyByValue = (enumerated, value: string) => {
return Object.keys(enumerated)[
Object.values(enumerated).indexOf(value as typeof enumerated)
];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment