The arrayLastIndexOf task searches an array and returns the last index (position) at which a given element is found. The task returns -1 if the element is not present. The array is searched backwards beginning at the fromIndex position. The returned index value is always relative to the beginning of the array — the first element is at index 0, the second at 1, and so on. The original array is not modified.
Use this task to find the last occurrence of a particular element in an array. For example, to find the last time a particular email appeared in an email list, use arrayLastIndexOf to retrieve its most recent index. If the email is not present, the result is -1.
In this example:
arr is statically set to ["a","b","c","a","b","c"].searchElement is "b".fromIndex is not provided, so the entire array is searched.index 4 — the last position of "b" in the array.
In this example:
arr is [1,2,3,2,5,2,3,2].searchElement is 2.fromIndex is -2, which means the search starts two positions from the end.index 5 — the last position of 2 within the search range.