AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Find method in javascript9/28/2023 As you can see if you click the button to run the code, the very first instance of an even number is returned – that being the number 2. When we then run the find() function, we pass the values as the first argument and the predicate function evenChecker as the second. We then assign a function to the evenChecker variable. So first off, we set up an array of integer values. This first example of the find function in Underscore makes use of a predicate function to search for and return the first instance of an even number. Let’s have a look at a few examples of find() in Underscore now. In other words, find() will iterate until it finds a true result for the predicate function, and at such time will return the object property value or array element value at the current position. The find() function can almost be thought of as a loop that stops iterating once the true value is found. The predicate function should return a boolean value, either true or false. The second parameter is a required function that must be passed which runs against each element in the array element or object property that was passed in as the first argument. The find() function takes an array or object as the first parameter. The signature has a familiar look in _.find(list, predicate, ) similar to the some() function we recently covered. The find() function is another very commonly used function in the Underscore JavaScript Library.
0 Comments
Read More
Leave a Reply. |