How to get the index of an element in array that matching a condition with TypeScript

1 Answer

0 votes
const arr = ['typescript', 'javascript', 'nodejs', 'typescript'];
  
const condition = (element) => element == 'typescript';
  
console.log(condition);
console.log(arr.findIndex(condition));
console.log(arr[arr.findIndex(condition)]); 
  
    
    
    
/*
run:
    
(element) => element == 'typescript' 
0 
"typescript" 
    
*/

 



answered May 8, 2022 by avibootz
edited May 16, 2022 by avibootz
...