Convert a string to an enum in Javascript
To convert a string to Enum in Typescript or angular follow the below steps.
1. Pass the given string to Enum object as a key.
2. If the string is part of the enum name entry the value will be returned.
3. And then cast it to the enum object to get enum type of string.
enum Day {
BeforeNoon = "AM",
AfterNoon = "PM"
}
function returnDayOfTime(day : Day){
console.log(day);
}