jskatas.org Continuously Learn JavaScript. Your Way.

Array API: array.findIndex()

Array.prototype.findIndex() find the index of an item in an array.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

Array.prototype.findIndex makes finding items in arrays easier

  • takes a compare function, returns the index where it returned true
  • returns the first position it was found at
  • returns -1 when nothing was found
  • the findIndex callback gets the item, index and array as arguments
  • combined with destructuring complex compares become short