> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.itential.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.itential.com/_mcp/server.

# arrayLastIndexOf

> Use the arrayLastIndexOf task to find the last index position of an element in an array.

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.

## Potential use case

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`.

## Properties

| Incoming        | Type   | Description                                                                                                                                                                                                          |
| :-------------- | :----- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `arr`           | Array  | Required. The array to search.                                                                                                                                                                                       |
| `searchElement` | Any    | Required. The element to locate.                                                                                                                                                                                     |
| `fromIndex`     | Number | Optional. The index position from which to start searching backwards. A positive number counts from the beginning (index `0`). A negative number counts from the end. If not provided, the entire array is searched. |

| Outgoing | Type   | Description                                                     |
| :------- | :----- | :-------------------------------------------------------------- |
| `index`  | Number | The last index where the element is found; `-1` if not present. |

## Example 1

In this example:

* The `arr` is statically set to `["a","b","c","a","b","c"]`.
* The `searchElement` is `"b"`.
* `fromIndex` is not provided, so the entire array is searched.
* The result is `index` `4` — the last position of `"b"` in the array.

![](/_fern-img/b4a8f19dff7996b5b8bc27f52aee4c7ad018cd039bb194ae86a29a35adf3396f.webp)

## Example 2

In this example:

* The `arr` is `[1,2,3,2,5,2,3,2]`.
* The `searchElement` is `2`.
* The `fromIndex` is `-2`, which means the search starts two positions from the end.
* The result is `index` `5` — the last position of `2` within the search range.

![](/_fern-img/356a712193bdf5833ae9a37d274d226cb20e383332afd55b5ad6528530e71c0d.webp)