Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
javascript enum to convert to list and check if the value is present in that enum

lets say i have an enum in javascript defined like this:

const myEnum = {
    A:'a',
    B:'b',
    C:'c',
    D:'d'
};

I have a character and I need to check whether it is present in the enum or not.

currently, I'm doing something like

if(value !== myEnum.A || value !==myEnum.B || ......) {
   //FAILURE
}

this is something of a problem how do I make it something like:

if(value not in myEnum.values){
   //FAILURE
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can use Object.values to check this

if (!Object.values(myEnum).includes(value)) {
    // Do what you want here
}

const myEnum = {
    A: 'a',
    B: 'b',
    C: 'c',
    D: 'd'
};

console.log(Object.values(myEnum).includes('a'));
console.log(Object.values(myEnum).includes('v'));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!