---
schema_version: "1"
id: 9fed2c7ed1a8f6b381b5d33f86a276f8dd9bd859641b53fe40a02f0726211017
title: lastIndexOf
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.11/dw-core-functions-lastindexof.md
canonical_url: https://docs.mulesoft.com/dataweave/2.11/dw-core-functions-lastindexof
source_site: docs.mulesoft.com
content_type: documentation
content_hash: d9572fd022b5989b91da45cbb21ce8c5a33719dd64e3aef949212722372a06b3
description: MuleSoft Documentation Site
release: "2.11"
latest: false
---
---
product: DataWeave
version: 2.11
---

# lastIndexOf

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## lastIndexOf(array: Array, value: Any): Number

Returns the index of the _last_ occurrence of the specified element in a given array or `-1` if the
array does not contain the element.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>array</code></p></td><td><p>The array of elements to search.</p></td></tr><tr><td><p><code>value</code></p></td><td><p>The value to search.</p></td></tr></tbody></table>

### Example

This example shows how `indexOf` behaves given different inputs.

#### Source

```DataWeave
%dw 2.0
output application/json
---
{
  present: ["a","b","c","d"] lastIndexOf "c",
  notPresent: ["x","w","x"] lastIndexOf "c",
  presentMoreThanOnce: ["a","b","c","c"] lastIndexOf "c",
}
```

#### Output

```Json
{
  "present": 2,
  "notPresent": -1,
  "presentMoreThanOnce": 3
}
```

## lastIndexOf(array: String, value: String): Number

Takes a string as input and returns the index of the _last_ occurrence of a given search string
within the input. The function returns `-1` if the search string is not present in the input.

_Introduced in DataWeave version 2.4.0._

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>string</code></p></td><td><p>The string to search.</p></td></tr><tr><td><p><code>value</code></p></td><td><p>A string value to search for within the input string.</p></td></tr></tbody></table>

### Example

This example shows how the `indexOf` behaves given different inputs.

#### Source

```DataWeave
%dw 2.0
output application/json
---
{
  present: "abcd" lastIndexOf "c",
  notPresent: "xyz" lastIndexOf "c",
  presentMoreThanOnce: "abcdc" lastIndexOf "c",
}
```

#### Output

```Json
{
  "present": 2,
  "notPresent": -1,
  "presentMoreThanOnce": 4
}
```

## lastIndexOf(array: Null, value: Any): Number

Helper function that enables `lastIndexOf` to work with a `null` value.

_Introduced in DataWeave version 2.4.0._
