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

PREVIOUS NEXT
Code Example
Typescript :: creating different objects in node.js 
Typescript :: check if element exists in array java 
Typescript :: stats python 
Typescript :: Environ 2.020.000 résultats (0,60 secondes) << Add Grepper Answer (a) Résultats de recherche Résultats Web 
Typescript :: typescript enum value to enum 
Typescript :: typescript initialize object 
Typescript :: split a column of lists pandas 
Typescript :: angular conditional directives 
Typescript :: javascrpit password 
Typescript :: top data scientists in the world 
Typescript :: How to return a new string with its first and last characters swapped 
Typescript :: .net framework core scaffhold exists table 
Cpp :: find largest number in vector c++ 
Cpp :: go read file to string 
Cpp :: remove last letter in string c++ 
Cpp :: qt qstring to float 
Cpp :: convert whole string to lowercase c++ 
Cpp :: int_min in cpp 
Cpp :: c++ string erase all occurrences 
Cpp :: priority queue ordered by second element 
Cpp :: loop through map c++ 
Cpp :: what is difference between single inverted and double inverted in programming languages 
Cpp :: qt qchar to lower 
Cpp :: filling dynamic array with a specific value in c++ 
Cpp :: climits in cpp 
Cpp :: calculate how many liters would be needed 
Cpp :: how to remove spaces from a string 
Cpp :: prime number program 
Cpp :: addition without arithmetic operators c++ 
Cpp :: helloworld in c++ 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =