1const array1 = [5, 12, 8, 130, 44];
2const search = element => element > 13;
3console.log(array1.findIndex(search));
4// expected output: 3
5
6const array2 = [
7 { id: 1, dev: false },
8 { id: 2, dev: false },
9 { id: 3, dev: true }
10];
11const search = obj => obj.dev === true;
12console.log(array2.findIndex(search));
13// expected output: 2
1// findIndex(callback fn)
2
3// .... return index (when condition meets)
4// .... return -1 (if condition not meets)
5
6const array = [5, 12, 8, 130, 44];
7
8/// it returns the index of number which satisfy the condition true
9const index = array.findIndex((item)=> item>10); //1
10
11/// now we can check what element at that index...
12console.log(array[index]); // array[1]
1var fruits = ["Banana", "Orange", "Apple", "Mango"];
2return fruits.indexOf("Apple"); // Returns 2