How to use DOT notation In Typescript
In this approach, we are using the dot notation to access enum values in typescript. It involves directly referencing the enum name followed by the enum member name (key) using a dot (.) syntax.
Syntax:
const enumValue = EnumName.EnumKey; EnumName is the name of the enum. EnumKey is the key of the enum whose value we want to access.
Example: The code below demonstrates how we can use the DOT notation to access enum values in typescript.
// Define Enum
enum GFG {
Org = "w3wiki",
Founder = "Sandip Jain",
Est = "2009"
}
// Access Enum using DOT notation
let value1 = GFG.Org;
let value2 = GFG.Founder;
let value3 = GFG.Est;
console.log(value1);
console.log(value2);
console.log(value3);
Output:
"w3wiki"
"Sandip Jain"
"2009"
How to Access Enum Values in TypeScript ?
Enums in TypeScript allow us to define a set of named constants. In this article, we will see how we can access enum values in typescript using different approaches which are as follows:
Table of Content
- Using bracket notation
- Using DOT notation
- Using Object Lookup
Contact Us