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.
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.
In this example:
arr variable is statically set to ["Apple","Pear","Banana"].searchElement is Banana.fromIndex defaults to 0.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.
