Layout Options

  • Fixed Header
    Makes the header top fixed, always visible!
  • Fixed Sidebar
    Makes the sidebar left fixed, always visible!
String IndexOf

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

Description

The lastIndexOf() method returns the position of the last occurrence of a specified value in a string.

This method has the form:

string.lastIndexOf(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 the length of the string

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.lastIndexOf("Java"));
</script>

This produces the following result:

Browser Support

Firefox IE Chrome Opera Safari