How to check if a string is contained in an array in JavaScript

1 Answer

0 votes
const arr = ['javascript', 'typescript', 'node.js'];
const str = 'javascript';

if (arr.includes(str)) {
  	console.log('yes');
} else {
  	console.log('no');
}


  
  
  
  
/*
run:
  
"yes"
  
*/

 



answered Jun 26, 2022 by avibootz

Related questions

1 answer 201 views
1 answer 221 views
1 answer 274 views
1 answer 260 views
1 answer 275 views
...