1//The findIndex() method returns the index of the first element
2//in the array that satisfies the provided testing function.
3//Otherwise, it returns -1, indicating that no element passed the test.
4const array1 = [5, 12, 8, 130, 44];
5
6const isLargeNumber = (element) => element > 13;
7
8console.log(array1.findIndex(isLargeNumber));
9// expected output: 3
10
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
1const array1 = [5, 12, 8, 130, 44];
2const search = element => element > 13;
3console.log(array1.findIndex(search));
4
5const array2 = [
6 { id: 1, dev: false },
7 { id: 2, dev: false },
8 { id: 3, dev: true }
9];
10const search = obj => obj.dev === true;
11console.log(array2.findIndex(search));