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

# lastIndexOf

> Use the lastIndexOf task to identify the last occurrence of a character or group of characters within a string by searching backwards.

The `lastIndexOf` string task identifies the last occurrence of a specific character or group of characters within a given string. It is similar to the `indexOf` task, with the exception that it begins searching from the end of the input string (rather than the beginning). The search proceeds backwards starting from a position identified by the `fromIndex` value. This method returns a number (`index`) representing the position where the specified search value occurs.

The `lastIndexOf` task does not change the value of the original string.

## Potential use case

Suppose you have a string that contains a date within it, and you need to locate the last slash `/` in the date value so that you can isolate the position of the "year" value. You could use the `lastIndexOf` task and extract it in a subsequent `slice` or `substring` task.

## Properties

| Incoming      | Type   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ------------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `str`         | String | Required. The string that contains the `searchValue` to be located.                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `searchValue` | String | Required. The value to search for in the `str`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `fromIndex`   | Number | Optional. The position in the string to begin the search. Leaving this value empty defaults to the end of the `str` and the full string is searched. When counting characters in a string, indexing begins at position `0` (the first `str` value). If the `fromIndex` value is greater than zero, the search will begin to the left of that specified index position. If `0` or a number less than `0`, only the first character in the string will be considered and the string searched backwards from there. |

| Outgoing | Type   | Description                                                                                                                                                          |
| -------- | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `index`  | Number | The position in the `str` where the `searchValue` was first identified. If the `searchValue` is not found in the specified `str`, the `index` property returns `-1`. |

## Example 1

In this example:

* The `str` variable has been statically set as `sales.department@itential.com`.
* The `searchValue` variable has been statically set as `"."` (a period).
* The `fromIndex` variable has been intentionally left empty, indicating the search should start at the end of the `str` value.
* The output `index` value will be `25` because the first instance of a period `"."`, starting from the end of the string, can be found at character position 25 (counting from the left) in the `str` variable.

![](/_fern-img/296703ea94aac7546d8ef2607ff89b35f006e3e98bd2bcd2ad8b1917e431a946.webp)

## Example 2

In this example:

* The `str` variable has been statically set as `sales.department@itential.com`.
* The `searchValue` variable has been statically set as `"."` (a period).
* The `fromIndex` variable has been set to `20`, indicating the search should start at position 20 of the `str` value and proceed to the left of that starting index position.
* The output `index` value will be `5` because the first instance of a period `"."`, starting left from position 20, can be found at character position 5 in the `str` variable.

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

## Example 3

In this example:

* The `str` variable has been statically set as `sales.department@itential.com`.
* The `searchValue` variable has been statically set as `"Z"`.
* The `fromIndex` variable has been intentionally left empty, indicating the search should start at the end of the `str` value.
* The output `index` value will be `-1`, because there is no `"Z"` in the `str` value.

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

## Example 4

In this example:

* The `str` variable has been statically set as `sales.department@itential.com`.
* The `searchValue` variable has been statically set as `"s"`.
* The `fromIndex` variable has been set to `-100`. Since negative numbers are treated as `0`, the search will begin at the first letter of the `str` value.
* The output `index` value will be `0` in reference to the first letter of the `str` value, which is the letter `"s"`.

![](/_fern-img/1eafb6657c9836ae19665f29b55015dce1b55e9f8415afb2aec8d1065a03dbbe.webp)