![]() |
The findIndex() function in TypeScript helps you find the index position of the first element in an array that meets a specified condition. If no element meets the condition, it returns -1. Syntaxarray.findIndex(callbackFn(value, index, array): boolean): number Parameters
Return Value:Returns the index position of the element in an array if it meets the given condition otherwise it will return -1. Example 1: Finding the Index of the First Even NumberIn this example we finds the index of the first even number in the numbers array using findIndex().
Output: 2 Example 2: Finding the Index of the First Odd NumberIn this example we finds the index of the first odd number in the
Output: 3 FAQs – TypeScript Array findIndex() MethodHow does findIndex() handle elements that do not satisfy the condition?
What happens if the callbackFn always returns false?
How does findIndex() handle empty arrays?
Can findIndex() be used to find the index of objects in an array?
What is the difference between findIndex() and indexOf()?
|
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 11 |