home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference

String.indexOf() Method


String.indexOf() Method---search a string


Navigator 2.0, Internet Explorer 3.0


string.indexOf(substring, start)



The substring that is to be searched for within string.


An optional integer argument that specifies the position within string at which the search is to start. Legal values are 0 (the position of the first character in the string) to string.length-1 (the position of the last character in the string). If this argument is omitted, then the search begins at the first character of the string.


The position of the first occurrence of substring within string that appears after the start position, if any, or -1 if no such occurrence is found.


String.indexOf() searches the string string from beginning to end to see if it contains an occurrence of substring. The search begins at position start within string, or at the beginning of string, if start is not specified. If an occurrence of substring is found, then String.indexOf() returns the position of the first character of the first occurrence of substring within string. Character positions within string are numbered starting with zero.

If no occurrence of substring is found within string, then String.indexOf() returns -1.


In Navigator 2.0 and 3.0, if start is greater than the length of string, then indexOf() returns the empty string rather than -1.

Previous Home Next
String.fontsize() Book Index String.italics()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell