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

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