Skip to main content

Array.index_of

index_ofconditionstart

Group: Values

Documentation

Returns the index of an element in the array. Returns Nothing if the element is not found.

Arguments

  • condition: Either the element to search for, a Filter_Condition or a predicate function to test each element.
  • start: The index to start searching from. If the index is negative, it is counted from the end of the array.

Examples

Find the index of an element in an array.

      [1, 2, 3].to_array.index_of 2 == 1

Find the index of the first palindrome.

      ["ab", "abab", "aba", "bbb"].to_array.index_of (s-> s == s.reverse) == 2