How to case insensitive check if array contains a string in JavaScript

1 Answer

0 votes
const arr = ['cpp', 'javascript', 'typescript', 'nodejs', 'c'];
const str = 'JAVASCRIPT';

const index = arr.findIndex(element => {
  	return element.toLowerCase() === str.toLowerCase();
});

console.log(index);
   
   
    
    
/*
run:
    
1
  
*/
 

 

 



answered Jul 13, 2022 by avibootz

Related questions

...