How to check if a value exists in an enum with TypeScript

1 Answer

0 votes
enum Languages {
  TypeScript = 'A',
  Java = 'B',
  Python = 'C',
  CPP = 9
}
 
const values = Object.values(Languages);

if (values.includes('B' as unknown as Languages)) {
    console.log('exists');
} else {
     console.log('not exists');
}

 
 
 
  
/*
  
run:
  
"exists"  
 
*/

 



answered Feb 28, 2022 by avibootz

Related questions

...