Array findindex() Method

This method returns the index of the first element in a given array that satisfies the provided testing function. Otherwise, -1 is returned.

Example: 

Here is an example of the basic use of the Array.findindex() method.

javascript




let array = [10, 20, 30, 110, 60];
 
function finding_index(element) {
    return element > 25;
}
 
console.log(array
    .findIndex(finding_index)
);


Output

2

Best-Known JavaScript Array Methods

An array is a special variable in all the languages that are used to store different elements. JavaScript array contains some built-in properties that every JavaScript developer should know how to use and when or where to use them. We can use them to add, remove, iterate, or manipulate data as per our requirements.

Similar Reads

Basic JavaScript Array Methods:

There are some Basic JavaScript array methods that every developer should know are:...

1. Array some() Method:

This method checks whether at least one of the elements of the array satisfies the condition checked by the argument function....

2. Array reduce() Method:

...

3. Array map() Method:

The array reduce() method in JavaScript is used to reduce the array to a single value and executes a provided function for each value of the array (from left to right) and the return value of the function is stored in an accumulator....

4. Array every() Method:

...

5. Array flat() Method:

The map() method in JavaScript creates an array by calling a specific function on each element present in the parent array. It is a non-mutating method. Generally, the map() method is used to iterate over an array and call the function on every element of an array....

6. Array flatMap() Method:

...

7. Array filter() Method:

This method checks whether all the elements of the array satisfy the given condition or not that is provided by a function passed to it as the argument....

8. Array findindex() Method:

...

9. Array find() Method:

This method creates a new array that contains more than arrays. Basically creates a simple array from an array that contains multiple arrays....

10. Array fill() Method:

...

11. Array forEach() Method:

This method is used to flatten the input array element into a new array. This method first of all map every element with the help of a mapping function, then flattens the input array element into a new array....

14. Array includes() Method:

...