# indexOf() and lastIndexOf() in Jira Automation

URL: https://goingstellar.ro/reference/smart-values/indexof/

indexOf() gives the position of the first match of a text inside another text, and lastIndexOf() the position of the last match. Both count from 0 and return -1 when the text is not found. You mostly feed the number to substring().

## Syntax

```
{{issue.summary.indexOf("text")}}
{{issue.summary.lastIndexOf("text")}}
```

## Arguments

- `text` (required: yes): The text to look for. The match is case-sensitive.

## Works on

- Fields: any text value, such as issue.summary or issue.description.
- Returns: a number, the position where the match starts, or -1.

## Examples

```
{{issue.summary.indexOf("Wo")}}
```

Find where the word World starts in Hello World!.

Result:

```
6
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.summary.indexOf("o")}}
```

First o in the summary.

Result:

```
4
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.summary.lastIndexOf("o")}}
```

Last o in the summary, for a summary with two of them.

Result:

```
7
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.summary.toLowerCase().indexOf("world")}}
```

Search without caring about capitals by lowering the text first.

Result:

```
6
```

Run on Jira Cloud on 29 Nov 2026.

```
{{issue.description.substring(0, issue.description.indexOf("."))}}
```

Keep only the first sentence of the description, up to the first full stop.

Result:

```
Checkout page redesign
```

Run on Jira Cloud on 29 Nov 2026.

## Where the documentation differs

- `{{issue.summary.indexOf("ello")}}`: run on Jira Cloud, 29 Nov 2026: the documentation says `2`, the actual result is `1`.
- `{{issue.summary.indexOf("d!")}}`: run on Jira Cloud, 29 Nov 2026: the documentation says `11`, the actual result is `10`.
- `{{issue.summary.lastIndexOf("wo")}}`: run on Jira Cloud, 29 Nov 2026: the documentation says `7`, the actual result is `-1`.
- `{{issue.summary.lastIndexOf("ll")}}`: run on Jira Cloud, 29 Nov 2026: the documentation says `4`, the actual result is `2`.
- `{{issue.summary.lastIndexOf("rl")}}`: run on Jira Cloud, 29 Nov 2026: the documentation says `9`, the actual result is `8`.

## Pitfalls

- Several results on the Atlassian page are off. On `Hello World!` the position of `ello` is 1, not 2, and `d!` starts at 10, not 11 (checked on Jira Cloud, November 2026). Positions start at 0 and name the first character of the match.
- lastIndexOf() also returns the position where the last match starts, not where it ends: `lastIndexOf("ll")` gives 2 and `lastIndexOf("rl")` gives 8.
- The search is case-sensitive. `lastIndexOf("wo")` and `indexOf("world")` both give -1 on `Hello World!`; lower the text first if case should not matter.
- A second argument for a start position is not accepted: `indexOf("o", 5)` renders an empty value, not 7.

## Related

- [substring()](https://goingstellar.ro/reference/smart-values/substring/)
- [substringAfter(), substringBefore(), substringBetween()](https://goingstellar.ro/reference/smart-values/substringafter-substringbefore/)
- [charAt()](https://goingstellar.ro/reference/smart-values/charat/)
- [left() and right()](https://goingstellar.ro/reference/smart-values/left-right/)
- [match()](https://goingstellar.ro/reference/smart-values/match/)
- [split()](https://goingstellar.ro/reference/smart-values/split/)

## Sources

- [Jira smart values: text fields (Atlassian Support)](https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/)

