![]() Let’s take some examples of using the JavaScript Array findIndex() method. It does not execute the method once it finds an element satisfying the testing method. Otherwise, if no data is found then the value of -1 is returned. ![]() Once the findIndex() finds such an element, it immediately returns the element’s index. The Javascript Array.findIndex () method is used to return the first index of the element in a given array that satisfies the provided testing function (passed in by the user while calling). The findIndex() executes the testFn on every element in the array until it finds the one where testFn returns a truthy value, which is a value that coerces to true. Narrator The array methods find and findIndex are used when you only need to return a single value within an array. If you omit the thisArg argument, the findIndex() function uses undefined. The thisArg is an optional object to be used this when executing the callback. The findIndex() method returns the index of the element that satisfies a testing function or -1 if no element passed the test.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |