Check out v4 of the Fauna CLI

v4 of the Fauna CLI is now in beta.

The new version introduces enhancements to the developer experience, including an improved authentication workflow. To get started, check out the CLI v4 quick start.

string.indexOf()

Get the index of the first matching substring within a String.

Signature

indexOf(pattern: String) => Number | Null

indexOf(pattern: String, start: Number) => Number | Null

Description

Returns the zero-based offset index for the first occurrence of a provided substring within the calling String. Starts at an optional start position in the calling String.

Parameters

Parameter Type Required Description

pattern

String

true

Substring to find the first occurrence of within the calling String.

start

Int

Zero-based index of the character to start searching for matches. Defaults to 0.

Return value

Type Description

Int

Zero-based index of the first matching occurrence in the calling String.

Null

No match not found.

Examples

  1. Get the starting location of the String 200, starting from the beginning of the calling string:

    "HTTP/1.1 200 OK".indexOf("200", 0)
    9
  2. Get the starting location of the String 200, starting at a location after the length of the calling string:

    "HTTP/1.1 200 OK".indexOf("200", 10)
    null

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!