Created
June 28, 2021 18:04
-
-
Save adarshaacharya/f2c23564880db03e36a8e64ed3523e7c to your computer and use it in GitHub Desktop.
convert enums into list of arrays
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
/** | |
* convert enums into list of arrays | |
*/ | |
enum UserRole { | |
Student = 'STUDENT', | |
Teacher = 'TEACHER', | |
} | |
const list = (enm: Record<string, unknown>): string[] => { | |
const values = [] as string[]; | |
for (const key in enm) { | |
values.push(enm[key] as string); | |
} | |
return values; | |
}; | |
const x = list(UserRole) | |
console.log(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment