How to find the index of the first element in array that equal to N in JavaScript

1 Answer

0 votes
const array = [3, 6, 1, 8, 9, 4, 5];

const number = (element) => element > 6;
const index = array.findIndex(number);

console.log(index);

console.log(array[index]);


  
    
    
/*
run:
    
3
8
    
*/

 



answered Nov 30, 2020 by avibootz
...