![]() 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. array is the array that the findIndex() was called upon. prototype.forEach method you need to pass in a callback, your callback should then accept a set of arguments so you can deal with each array item however you.index is the index of the current element being processed.element is the current element in the array. ![]() The testFn is a function to execute on each element in the array until the function returns true, indicating that the element has been found. The findIndex() takes two arguments: 1) testFn FindIndex( testFn( element ]) ) Code language: CSS ( css )
0 Comments
Leave a Reply. |