Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

check if enum contains value typescript

enum EList {
  ITEM_FOO = 'fooData',
  ITEM_BAR = 'barData'
}

const lookingForKey = 'ITEM_BAR'
const lookingForValue = 'barData'

// test if `lookingForKey` exists within `EList`
console.log(Object.keys(EList).some((v) => v === lookingForKey))

// test if `lookingForValue` exists within `EList`
console.log(Object.values(EList).some((v) => v === lookingForValue))
Comment

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"]
Comment

typescript enum includes value

if ((<any>Object).values(Vehicle).includes('car')) {
    // Do stuff here
}
Comment

javascript enum includes value

if (Object.values(Vehicle).includes('car')) {
    // Do stuff here
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: endurance testing 
Typescript :: typescript interface define a map key value pairs 
Typescript :: INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. 
Typescript :: how to use indexOf in typesript 
Typescript :: typescript new instance of interface 
Typescript :: node scripts delay 
Typescript :: typescript mocha Cannot use import statement outside a module 
Typescript :: javascrpit password 
Typescript :: how to separate a string into 2 lists of numbers and letters python 
Typescript :: Number of power set of {a, b}, where a and b are distinct elements. 
Typescript :: how to setup netflix workflow worker 
Cpp :: arduino uno hello world 
Cpp :: fast i/o in c++ 
Cpp :: c++ get filename from path 
Cpp :: how to print list in c++ 
Cpp :: fahrenheit to kelvin formula 
Cpp :: check gpu usage jetson nano 
Cpp :: Count set bits in an integer c++ 
Cpp :: c++ custom compare in set 
Cpp :: hello world c++ visual studio 
Cpp :: how to get a random number between two numbers in c++ 
Cpp :: cv2.threshold c++ 
Cpp :: c++ execution time 
Cpp :: non stoichiometric nacl is yellow 
Cpp :: how to use comparator funtion in priority queue in c++ 
Cpp :: c++ random number generator 
Cpp :: xmake set binary name 
Cpp :: default rule of five c++ 
Cpp :: c++ string to integer without stoi 
Cpp :: c++ vector iterator 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =