Description
The indexOf() method returns the position of the first occurrence of a specified value in a string.
This method has the form:
string.indexOf(search,start)
Parameter | Description |
---|---|
search | (required) The string to search for |
start | (optional) The start position in the string to start the search. If omitted, the search starts from position 0 |
Note: This method is case sensitive.
Examples
The following example shows the basic use of this method.
<script>
var s = "Hello from JavaScript";
document.write(s.indexOf("Java"));
</script>
This produces the following result:
Browser Support
Firefox | IE | Chrome | Opera | Safari |
---|---|---|---|---|