---
schema_version: "1"
id: e72a9fb4e3852fb8107a21958dcd5437e33b76bf884ced54cafc3a3acc959226
title: indexOf
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-core-functions-indexof.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-core-functions-indexof
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 1dc11a339eb0d61e1be2733a7b0190bb994b19d1e09e476cc87e0174ecb49220
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# indexOf

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

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

Returns the index of the _first_ occurrence of the specified element in this array, or `-1` if this
list 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"] indexOf "c",
  notPresent: ["x","w","x"] indexOf "c",
  presentMoreThanOnce: ["a","b","c","c"] indexOf "c",
}
```

#### Output

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

## indexOf(theString: String, search: String): Number

Returns the index of the **first** occurrence of the specified String in this String.

_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>theString</code></p></td><td><p>The string to search.</p></td></tr><tr><td><p><code>search</code></p></td><td><p>The string to find within <code>theString</code>.</p></td></tr></tbody></table>

### Example

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

#### Source

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

#### Output

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

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

Helper method to make indexOf null friendly

_Introduced in DataWeave version 2.4.0._
