JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods
Arrays

JAVASCRIPT lastIndexOf() METHOD

The lastIndexOf() method returns the position of the last occurrence of a specified search string or search character to look for in a string. The lastIndexOf() method is case sensitive.

The lastIndexOf() method takes the string or character to search for as a compulsory argument and an optional to start from argument (counted backwards). Always remember that the first position always starts at 0 (and not 1). The lastIndexOf() method returns a -1 if no occurrences are found.

The general format is:

string.lastIndexOf(tosearchfor, tostartfrom[optional]);

Example Without The Optional tostartfrom Argument:

<script type="text/javascript">

var string="The brown box";

document.write(string.lastIndexOf("b"));

</script>

The above will output:



Example With The Optional tostartfrom Argument:

<script type="text/javascript">

var string="The brown box";

document.write(string.lastIndexOf("r", 5));

</script>

The above will output:



Example With No Match:

<script type="text/javascript">

var string="The brown box";

document.write(string.lastIndexOf("f"));

</script>

The above will output:



See Also:

anchor() big()
blink() bold()
charAt() charCodeAt()
concat() fixed()
fontcolor() fontsize()
fromCharCode() indexOf ()
italics () lastIndexOf()
link() match()
replace () search()
slice() small()
split() strike()
sub() substr()
substring() sup()
toLowerCase() toUpperCase()
toSource() valueOf ()

Home | Privacy Policy | Terms Of Use | Contact Us