Docly Developers
Function Updated 17 Oct 2026

String.indexOf(text, [position])

Searches the entire calling string, and returns the index of the first occurrence of the specified substring.

Parameters

textstringrequired

Text to search for. The search is case-sensitive.

positionnumberoptional

Index to start searching from. Default 0; values outside the string are clamped.

Returns

The index of the first occurrence at or after position, or -1 if not found.

Example

Mixed HTML (or any text file) with inline JavaScript between hash signs.
#{
    var text = "This is a test";
    var search = "test";
    var notfound = "xyz";
}#

<b>Found in string:</b>
#{
    var index = text.indexOf(search);
    write(index);
}#


<b>Not found in string:</b>
#{
    index = text.indexOf(notfound);
    write(index);    
}#