arr.find

arr.find

  • The methods arr.indexOf, arr.lastIndexOf and arr.includes have the same syntax and do essentially the same as their string counterparts, but operate on items instead of characters.
  • Imagine we have an array of objects. How do we find an object with the specific condition? Here the arr.find method comes in handy.
  • The find method looks for a single (first) element that makes the function return true.

Syntax

Let result = arr.find(function(item, index, array) {
  // should return true if the item is what we are looking for
});

Syntax

Let results = arr.filter(function(item, index, array) {
  // should return true if the item passes the filter
});

Related concepts

arr.find — Structure map

Clickable & Draggable!

arr.find — Related pages: