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

1 Answer

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

 



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