String.indexOf() : indexOf « String « JavaScript Tutorial






Syntax

string.indexOf(string, num)
    string.indexOf(string)

The indexOf() method returns the indexed start position of the string passed.

You can specify an index, defined by num, to start your search for the string specified.

This method is the same as the String.lastIndexOf() method, but it starts at the beginning of the string.

<html>
    <script language="JavaScript">
    <!--
    var myString = new String("Hello, World!");

    document.write(myString.indexOf(" ") + '<br>');

    document.write(myString.indexOf("l", 4));

    document.close();

    -->
    </script>
</html>








6.16.indexOf
6.16.1.String.indexOf()
6.16.2.Get a substring index
6.16.3.Use indexOf method the search a substring