arrayIndexOf

The arrayIndexOf task returns the first index (position) at which a given element can be found in the array. The task returns -1 if the element is not found.

Potential use case

Suppose you have a list of email addresses and want to determine if an email record is listed in the correct department. The arrayIndexOf task checks whether the email exists and returns the index position where it occurs. If the email is not found, it returns -1.

Properties

IncomingTypeDescription
arrArrayRequired. The array to search.
searchElementAnyRequired. The element to search for.
fromIndexNumberOptional. The index position to start the search. Defaults to 0.
OutgoingTypeDescription
indexNumberThe position of the element in arr. Returns -1 if not found.

Example

In this example:

  • The arr variable is statically set to ["Apple","Pear","Banana"].
  • The searchElement is Banana.
  • The fromIndex defaults to 0.
  • The index result returns 2, indicating that Banana is at index position two in the array.

Array indexing is zero-based: the first element is at position 0, the second at 1, and so on.

arrayIndexOf task returning index 2 for Banana in the array