Availability
JavaScript 1.0; JScript 1.0, ECMAScript v1
Synopsis
string.lastIndexOf(substring)string.lastIndexOf(substring, start)
Arguments
substring
The substring that is to be searched for within
string.
start
An optional integer argument that specifies the position within
string where the search is to start. Legal
values are from 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, the search begins with the last character of the string.
Returns
The position of the last occurrence of
substring within
string that appears before the
start position, if any, or -1 if no
such occurrence is found within string.
Description
String.lastIndexOf( ) searches the string from end
to beginning to see if it contains an occurrence of
substring. The search begins at position
start within
string, or at the end of
string if start
is not specified. If an occurrence of
substring is found,
String.lastIndexOf( ) returns the position of the
first character of that occurrence. Since this method searches from
end to beginning of the string, the first occurrence found is the
last one in the string that occurs before the
start position.
If no occurrence of substring is found,
String.lastIndexOf( ) returns -1.
Note that although String.lastIndexOf( ) searches
string from end to beginning, it still
numbers character positions within string
from the beginning. The first character of the string has position 0
and the last has position
string.length-1.
See Also
String.charAt( ), String.indexOf( ), String.substring( )
•
Table of Contents
•
Index
•
Reviews
•
Examples
•
Reader Reviews
•
Errata
JavaScript: The Definitive Guide, 4th Edition
By
David Flanagan
Publisher
: O'Reilly
Pub Date
: November 2001
ISBN
: 0-596-00048-0
Pages
: 936
Slots
: 1
This fourth edition of the definitive reference to
JavaScript, a scripting language that can be embedded
directly in web pages, covers the latest version of the
language, JavaScript 1.5, as supported by Netscape 6 and
Internet Explorer 6. The book also provides complete
coverage of the W3C DOM standard (Level 1 and Level 2),
while retaining material on the legacy Level 0 DOM for
backward compatibility.