Complete the code to declare a numeric enum named Direction.
enum Direction {
Up = [1],
Down,
Left,
Right
}The first enum member defaults to 0 if not assigned. Here, we explicitly assign 0 to Up.
Complete the code to get the name of the enum member with value 2.
let directionName = Direction[[1]];Numeric enums support reverse mapping. Using the numeric value 2 returns the member name 'Left'.
Fix the error in accessing the enum member name by value.
console.log(Direction[[1]]);Direction[1] returns 'Down' because Down is the second member with value 1.
Fill both blanks to create a reverse mapping lookup for the enum member with value 3.
const value = [1]; const name = Direction[[2]];
Assign 3 to value, then use Direction[value] to get the member name 'Right'.
Fill all three blanks to declare a numeric enum with custom start, then get the name of the member with value 101.
enum Status {
Active = [1],
Inactive,
Pending
}
const code = [2];
const statusName = Status[[3]];Start enum at 100, so Inactive is 101. Assign 101 to code, then use Status[code] to get 'Inactive'.