Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

check if enum contains value typescript

// typescript is not executed by browsers, thus typescript's enums don't exist
// at runtime, it's interpreted as a plain js object : it's possible to use
// Object methods like Object.values(), Object.entries(), Object.keys()... 

// this enum
enum MyEnum {
  FIRST="my first value"
  SECOND="second value"
}
// transforms into :
const MyEnumInJs = {
  FIRST:"my first value",
  SECOND:"second value"
}

Object.values(MyEnum) // returns ['my first value', 'second value']
Object.keys(MyEnum) // returns ["FIRST", "SECOND"]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #enum #typescript
ADD COMMENT
Topic
Name
7+1 =