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

1 Answer

0 votes
const arr = ['php', 'cpp', 'javascript', 'typescript', 'nodejs', 'c'];
const str = 'TYPESCRIPT';
 
const index = arr.findIndex(element => {
    return element.toLowerCase() === str.toLowerCase();
});
 
console.log(index);
    
    
     
     
/*
run:
     
3
   
*/

 



answered Jul 13, 2022 by avibootz

Related questions

...