strings.index() function

The strings.index() function returns the index of the first instance of a substring in a string. If the substring is not present, it returns -1.

*Output data type: Integer*

  1. import "strings"
  2. strings.index(v: "go gopher", substr: "go")
  3. // returns 0

Parameters

v

The string value to search.

*Data type: String*

substr

The substring to search for.

*Data type: String*

Examples

Find the first occurrence of a substring
  1. import "strings"
  2. data
  3. |> map(fn: (r) => ({
  4. r with
  5. the_index: strings.index(v: r.pageTitle, substr: "the")
  6. })
  7. )

Related articles