Documentation

strings.lastIndex() function

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

Output data type: Integer

import "strings"

strings.lastIndex(v: "go gopher", substr: "go")

// returns 3

Parameters

v

The string value to search.

substr

The substring to search for.

Examples

Find the last occurrence of a substring
import "strings"

data
    |> map(fn: (r) => ({r with the_index: strings.lastIndex(v: r.pageTitle, substr: "the")}))

Was this page helpful?

Thank you for your feedback!


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.