Learn about the Array findIndex method in JavaScript

Find an item in an array with the ‘findIndex’ method in JavaScript.

Photo by Gratisography from Pexels

The method returns the index of the first element of the array if the callback function passed to the method returns true, otherwise returns -1

Syntax

  • → A function to execute on each value in the array until the function returns , indicating that the satisfying element was found.
  • → Optional object to use as when executing .

The takes three arguments

  • → current processing element
  • → index of the element processing
  • → array in which findIndex method called.

Note

  • once the callback returns the index, it will not process the remaining elements.

Unlike other array methods such as , is run even for indexes with unassigned values.

Extras :

The method, which returns the value of an array element, instead of its index.

You can find the implementation details of method here.

Articles related to JavaScript.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store