AI Workshop: learn to build apps with AI →
Arrays + functions: find() and findIndex()

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


find() is used to find an item in the array.

We pass a function to it, and we get back the first item that returns true from it.

a.find((element, index, array) => {
  //return true or false
})

Returns undefined if not found.

Example:

const itemFound = items.find((item) => item.name === 'b')

findIndex() is similar but instead of the item, like find(), it returns the index of the first item that returns true, and if not found, it returns -1:

a.findIndex((element, index, array) => {
  //return true or false
})

Lessons in this unit:

0: Introduction
1: map()
2: filter()
3: reduce()
4: sort()
5: ▶︎ find() and findIndex()
6: forEach()