Complete the code to declare a numeric enum named Direction.
enum Direction {
Up = [1],
Down,
Left,
Right
}The first member of a numeric enum defaults to 0 if not assigned. Here, we explicitly assign 0 to Up.
Complete the code to get the numeric value of Direction.Left.
let leftValue: number = Direction.[1];To get the numeric value of the enum member Left, use Direction.Left.
Fix the error in the code to get the enum member name from its numeric value.
let directionName: string = Direction[[1]];To get the name of the enum member from its numeric value, use the numeric index, here 2 for Left.
Fill both blanks to declare a numeric enum with custom starting value and get its member value.
enum Status {
Active = [1],
Inactive,
Pending
}
let activeValue = Status.[2];Assign 5 to Active to start numbering at 5. Then access Status.Active to get its value.
Fill all three blanks to create a numeric enum and get the name of a member by its value.
enum Color {
Red = [1],
Green,
Blue
}
let colorValue = Color.[2];
let colorName = Color[[3]];Start enum at 10 for Red, so Green is 11. Access Color.Green for value 11, then Color[11] returns 'Green'.