I am confused between the difference between the two function indexOf and find Index in an array.
The documentation says
findIndex - Returns
The main difference are the parameters of these functions:
-> Array.prototype.indexOf() :
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.indexOf("Apple");
The result of a will be: 2
->Array.prototype.findIndex() :
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
function myFunction() {
document.getElementById("demo").innerHTML =
ages.findIndex(checkAdult);
}
The result will be: 2