To use the findIndex function from Lodash, follow the steps below:
index.tsx19 chars2 lines
findIndex function from Lodash:index.tsx41 chars2 lines
Alternatively, if you are using ES6 modules:
index.tsx36 chars2 lines
findIndex function, passing in an array and a predicate function to search for the index of the first element that matches the predicate:index.tsx229 chars10 linesIn this example, findIndex is searching the users array for the index of the object with a name property equal to 'Charlie'.
That's it! findIndex will return the index of the first element that matches the predicate function, or -1 if no elements match.
gistlibby LogSnag