_.findIndex
is a function in the Underscore library that is used to find the index of the first element in an array that matches the given condition.
Here is the syntax for using _.findIndex
:
index.tsx41 chars2 lines
array
(Array): The array to search.predicate
(Function): The function to apply to each element in the array. The function should return a boolean value indicating whether the element satisfies the condition.[context]
(Object): The context to use as this
when executing the predicate function.Example usage:
index.tsx207 chars9 lines
In the example above, the _.findIndex
function is called on the numbers
array with a predicate function that checks whether each number is even or odd. The function returns the index of the first even number, which is 1
.
gistlibby LogSnag