TypeScript Array findIndex() Method Last Updated : 12 Jul, 2024 Comments Improve Suggest changes Like Article Like Report 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): numberParameterscallbackFn: A function that is called for each element in the array. It takes three arguments:element: Here we have to pass the current element that is being processed in the array.index: Here we have to pass the index position of the current component which is being processed in the array. array: Here we have to pass the array on which findIndex() was called upon. 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(). TypeScript const numbers: number[] = [1, 3, 8, 5, 2]; const evenIndex: number = numbers.findIndex( (number: number) => number % 2 === 0 ); console.log(evenIndex); Output: 2Example 2: Finding the Index of the First Odd NumberIn this example we finds the index of the first odd number in the numbers array using findIndex(). TypeScript const numbers: number[] = [2, 4, 8, 5, 2]; const oddIndex: number = numbers.findIndex( (number: number) => number % 2 === 1 ); console.log(oddIndex); Output:3 Comment More info P pankajbind Follow Improve Article Tags : TypeScript Explore TypeScript Tutorial 8 min read TypeScript BasicsIntroduction to TypeScript 3 min read Difference between TypeScript and JavaScript 4 min read How to install TypeScript ? 3 min read Hello World in TypeScript 2 min read How to execute TypeScript file using command line? 2 min read Variables in TypeScript 6 min read What are the different keywords to declare variables in TypeScript ? 4 min read Identifiers and Keywords in TypeScript 2 min read TypeScript primitive typesData types in TypeScript 3 min read TypeScript Numbers 4 min read TypeScript String 4 min read Explain the concept of null and its uses in TypeScript 3 min read TypeScript Object typesWhat are TypeScript Interfaces? 4 min read TypeScript class 4 min read How enums works in TypeScript ? 4 min read TypeScript Tuples 4 min read TypeScript other typesWhat is any type, and when to use it in TypeScript ? 3 min read How to Create an Object in TypeScript? 4 min read What is an unknown type and when to use it in TypeScript ? 3 min read Explain the purpose of never type in TypeScript 3 min read TypeScript combining typesTypeScript Union 3 min read What are type aliases and how to create it in Typescript ? 3 min read TypeScript AssertionsExplain Type assertions in TypeScript 3 min read TypeScript FunctionsHow to write a function in Typescript ? 4 min read How to achieve function overloading in TypeScript ? 2 min read Explain the arrow function syntax in TypeScript 2 min read TypeScript toPrecision() Function 1 min read TypeScript toFixed() Function 2 min read TypeScript toLocaleString() Function 2 min read TypeScript toString() 1 min read TypeScript interfaces and aliasesWhat are TypeScript Interfaces? 4 min read What are type aliases and how to create it in Typescript ? 3 min read TypeScript classesHow to Extend an Interface from a class in TypeScript ? 2 min read How to Create an Object in TypeScript? 4 min read How to use getters/setters in TypeScript ? 5 min read TypeScript Inheritance 3 min read When to use interfaces and when to use classes in TypeScript ? 4 min read Generics Interface in typescript 5 min read How to use property decorators in TypeScript ? 4 min read Like