indexOf
Returns the index of the first occurrence of a substring within a string. Returns -1 if the substring is not found.
Syntax
indexOf(input, substring)or chained:
<string>.indexOf(substring)Arguments
input (
string, optional when chained) - The string to search in.substring (
string) - The substring to search for.
Examples
Find a substring
indexOf("hello world", "world")
// 6Chained usage
"foobar".indexOf("bar")
// 3Not found
"hello".indexOf("xyz")
// -1CLI usage
Check if a substring exists
Last updated