Created
July 6, 2022 12:42
-
-
Save NewEXE/f8b466f8d46d144e76e1c270d237ecd0 to your computer and use it in GitHub Desktop.
Get enum key by value (Typescript)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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