Let’s take some examples of using the JavaScript Array findIndex() method. Once the findIndex() finds such an element, it immediately returns the element’s index. 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. 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. It is faster if you want to find a specific element: var ages 3, 10, 18, 20 console.log (ages.indexOf (10)) returns: 1 Index counting starts at 0, so the first element index is 0. array is the array that the findIndex() was called upon. You can find an exact element index with the indexOf function of Array, but you can't pass a predicate.index is the index of the current element being processed.
0 Comments
Leave a Reply. |