April 2018
Beginner to intermediate
426 pages
10h 19m
English
Consider the following example:
let numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
function multipleOf13(element, index, array) {
return (element % 13 == 0);
}
console.log(numbers.find(multipleOf13));
console.log(numbers.findIndex(multipleOf13));
The find and findIndex methods receive a callback function that will search for a value that satisfies the condition presented in the testing function (callback). For this example, we are looking to see whether the array numbers contain any multiple of 13.
The difference between find and findIndex is that the find method returns the first value of the array that satisfies the proposed condition. The findIndex method, on the other hand, returns the ...