How to get the index of an element in array that matching a condition with Node.js

1 Answer

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

 



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