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 infoAdvertise with us Next Article TypeScript Array findIndex() Method pankajbind Follow Improve Article Tags : JavaScript Web Technologies TypeScript Similar Reads TypeScript Array indexOf() Method The Array.indexOf() method in TypeScript is used to find the index of the first occurrence of a specified element in an array. If the element is not found, it returns -1.Syntaxarray.indexOf(searchElement[, fromIndex])Parameter: This method accepts two parameters as mentioned above and described belo 2 min read TypeScript Array lastIndexOf() Method The Array.prototype.lastIndexOf() method in TypeScript is used to find the last index at which a given element can be found in the array, searching backwards from the fromIndex. It returns the index of the found element, or -1 if the element is not present.Syntax:array.lastIndexOf(searchElement[, fr 2 min read TypeScript Array find() method with Examples The find() method in TypeScript searches the first element in the array, testing the function. If no element in the array satisfies the condition, the method returns undefined.Stops execution once a match is found (efficient).Returns the matched element, not its index.Does not modify the original ar 3 min read JavaScript Array findIndex() Function JavaScript arr.findIndex() function is used to find the index of the first element that satisfies the condition checked by the argument function from the given array. Suppose you want to find the index of the first element of the array that is even. Syntax: array.findIndex(function(element, index, a 3 min read JavaScript Array findIndex() Method The findIndex() method in JavaScript is a powerful tool for locating the first element in an array that satisfies a provided testing function. This guide provides a comprehensive overview of how to use findIndex() effectively, enhancing your ability to manipulate arrays. Syntax array.findIndex(funct 5 min read JavaScript Array findLastIndex() Method The Javascript findLastIndex() method is used to find the index of the last element in an array that matches the specified condition. It works by iterating over the array from the end to the beginning and returning the index of the first element that satisfies the condition specified in a callback f 2 min read JavaScript indexOf() method in an Object Array In JavaScript, indexOf() methods provide the first index at which the given element exists, and -1 in case it is not present in the array. Syntax: indexOf(element)indexOf(element, start);Parameters: element: the element to be searched in the input arraystart: the index from which the search has to b 2 min read JavaScript Array indexOf() Method The indexOf() method in JavaScript is used to find the position of the first occurrence of a specific value in an array. If the value is not present, it returns -1. This method is handy for quickly determining where a particular item is located within an array.Syntax:array.indexOf(element, start)Par 3 min read JavaScript - Find Index of a Value in Array Here are some effective methods to find the array index with a value in JavaScript.Using indexOf() - Most Used indexOf() returns the first index of a specified value in an array, or -1 if the value is not found. JavaScriptconst a = [10, 20, 30, 40, 50]; // Find index of value 30 const index = a.inde 2 min read JavaScript typedArray.lastIndexOf() Method The typedArray.lastIndexOf() is an inbuilt function in JavaScript which is used to return the last index of the typedArray at which a given element is present otherwise it returns -1 if the element is not present. Syntax: typedArray.lastIndexOf(search_Element, from_Index]) Parameters: It accepts two 2 min read Like