Accessing Enum Values
In this lesson, we will see how to access information from an enum.
We'll cover the following
TypeScript map objects to allow access
A variable set with an enum
that has a number
lets you access the enum
name from the integer. However, an enum
with string values does not have this capability. This means you can use the enum
name followed by the name of the constant to get the value. Also, with a number, you can also use the value to return the name.
For example, an enum
called Orientation
with East
, West
, North
, South
could use Orientation.East
to get the value zero or use Orientation[0]
to get East
. This works because TypeScript generates a map object which gives you access using the name of the entry or the value.
Get hands-on with 1200+ tech skills courses.