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

PREVIOUS NEXT
Code Example
Typescript :: typescript if then shorthand 
Typescript :: python shuffle two lists together 
Typescript :: ERROR: Could not find a version that satisfies the requirement mediapipe (from versions: none) ERROR: No matching distribution found for mediapipe 
Typescript :: how to register assets in flutter 
Typescript :: ts(7053) 
Typescript :: function that redirects to another page react 
Typescript :: how to display an image in flutter using its filepath 
Typescript :: how to find uncommon elements in two lists in python 
Typescript :: adjust distance of subplots in python 
Typescript :: typscript to string 
Typescript :: capacitor base64 to file 
Typescript :: after effects free download 
Typescript :: Check if a temporary table exists and delete if it exists 
Typescript :: ionic 4 reset form 
Typescript :: key value typescript 
Typescript :: typescript ge t current screen resolution 
Typescript :: angular firestore timestamp date pipe 
Typescript :: react router dom private route typescript 
Typescript :: angular http 
Typescript :: make an interface iterator typescript 
Typescript :: array with multiple types in ts 
Typescript :: debounce typescript 
Typescript :: 10 digit mobile number validation pattern in javascript 
Typescript :: typescript with babel 
Typescript :: add correct host key in /root/.ssh/known_hosts to get rid of this message 
Typescript :: axios typescript 
Typescript :: flutter check if app is in foreground 
Typescript :: ionic cannot be loaded because running scripts is disabled on this system. vscode 
Typescript :: get n random elements from list java 
Typescript :: Contract in ethers.js 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =