Skip to main content

Array.find

findcondition start if_missing

Group: Selections

Documentation

Returns the first element of the array that satisfies the condition or if_missing if no elements of the array satisfy it.

Arguments

  • condition: A Filter_Condition or a function that takes an element and returns a boolean value specifying if it satisfies the condition.
  • start: The index to start searching from. If the index is negative, it is counted from the end of the array.
  • if_missing: Value returned if no element satisfies the predicate.

Examples

Finding a first element of the array that is larger than 3.

      [1, 2, 3, 4, 5].to_array.find (> 3)