Here is an example of how to work with enums in TypeScript:
export enum Category {
Action = 1,
Option = 2,
RealEstateFund = 3,
FuturesContract = 4,
ETFs = 5,
BDRs = 6
}
The following function can be used to retrieve the enum indexes:
export function getEnumIndexes(object: any) {
return Object.keys(object).filter(key => !isNaN(Number(object[key])));
}
When populating an HTML select element with this enum, you may encounter a scenario where the enum member names are displayed instead of the indexes. To resolve this issue, you can use the index instead of the member name by retrieving it using the function provided above.