In this example I am using the array find method to just fine the first number in an array that is greater than 2.
When writing the call back function that will be passed to the array find method there are a number of arguments that will be available in the body of the call back function. The first argument is the current value of an element in the array, the second is that values index in the array, and the final argument is a reference to the array itself.
If I want to get not just one element, but all elements that meet a condition I can use the array filter method. This will create and return a new array where each element is an element that meets the conditon that was given with a callback rather than just the first match.
Say I want to use the array find method as it will work just fine, but I just want to reverse the order in which the array find method works. For this the array reverse method can reverse the order of all the elements, and then it will get the first element that will meet the condition from what was the end of the array before hand.
The Math.max and Math.min methods of the Math object can be used as a way to go about finding the largest, or smallest number in an array when using with the apply function prototype method. To do this I just need to pas something like null as the value for the value of this when calling the apply method off of the Math.max, or Math.min method, and then the array as the second argument for the apply method.
When it comes to finding the smallest value for an array of objects I will want to do something to create an array of numbers that I can then pass to one of these math methods. Doing something with the array map method can be done to furnish such an array from an array of objects.
2.4 - The array sort method to change the order of the whole array where the first element is the best match
This way I am sorting the whole array so that it is in order with respect to the condition in which I want to find something, rather than just getting the first match from left to right which would be the case when just using the array find method by itself.
The array fine method is then one way to go about finding one element in an array that will match a given condition in the from of an expression in a call back function. However there are many other methods and features that can also be used to get the first element, as well as all the elements that meet a condition. There are also ways of going about creating a whole new array from a source array, creating values that will be used as a kind of score, and then sorting the new array by that score or index value.