Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Findexof.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fstring%2Findexof.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `indexOf`

## Description

Returns the position of the first occurrence of a substring within a string.

The index is zero-based. If the substring is not found, the function returns `-1`.

## Syntax

Like many functions in DataPrime, `indexOf` supports<!-- --> [two notations](https://coralogix.com/docs/docs/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
indexOf(value: string, substring: string): number
```

```
(value: string).indexOf(substring: string): number
```

## Arguments

| Name        | Type     | Required | Description                          |
| ----------- | -------- | -------- | ------------------------------------ |
| `value`     | `string` | **true** | The full string to search (haystack) |
| `substring` | `string` | **true** | The substring to locate (needle)     |

## Example

**Extract a value from a key-value style string**

Consider the following document:

```
{

    "msg": "result=Some value"

}
```

Use `indexOf` to find the position of `=` and then extract everything after it.

### Example query

* Function notation
* Method notation

```
create index_of_value from (indexOf(msg, '='))
```

```
create index_of_value from (msg.indexOf('='))
```

### Example output

With the index known, you can extract the substring:

```
create value from msg.substr(index_of_value)
```

Result:

```
{

    "msg": "result=Some value",

    "index_of_value": 6,

    "value": "Some value"

}
```
