String.indexOf()
JavaScript1.0+, JScript1.0+, ECMAScript1.0+ NES2+, Nav2+, IE3+, Opera3+ Syntax
string.indexOf(string, num) string.indexOf(string)
Description
The indexOf() method of an instance of the String object returns the indexed start position of the string passed. Additionally, you can specify an index, defined by num in the syntax definition, 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.
Example
Listing 6.240 creates a simple instance of the String object. This instance is then passed to the indexOf() method on two occasions with the result written to the user's page. The first occasion looks for a space in the string, which ...
Get Pure JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.