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
textstringrequiredText to search for. The search is case-sensitive.
positionnumberoptionalIndex 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);
}#The template above produces this output:
<b>Found in string:</b>
10
<b>Not found in string:</b>
-1