JavaScript lastIndexOf () method
Examples
Find the location of array elements "Apple" appears:
var a = fruits.lastIndexOf ( "Apple");
a output:
Examples of the above output means that "Apple" is located in the array in the first two positions.
try it"Definition and Usage
lastIndexOf () method returns the position of a specified string value last appeared in a string at a specified location from the search forward.
If you want to retrieve the string value is not present, the method returns -1.
This method is retrieved from the head to the tail string stringObject, to see if it contains a substring searchvalue. Start retrieving location (not specified fromindex time) at the end of the fromindex string or strings. If you find a searchvalue, the first character position in stringObject searchvalue in return. stringObject character position is zero-based.
Tip: If you want to find the first occurrence of the string, use the indexOf () method .
Browser Support
All major browsers support lastIndexOf () property, but in Internet Explorer 8 and earlier versions of IE does not support this method.
grammar
Parameter Values
parameter | description |
---|---|
item | Required. Provisions need to retrieve a string value. |
start | The optional integer parameter. Specified in the string to begin the search location. Its legal value of between 0 stringObject.length - 1. If the argument is omitted, it will start retrieving from the last character of the string. |
return value
Type | description |
---|---|
Number | If there searchvalue before stringObject in fromindex position, it returns the position of appearing last searchvalue. |
technical details
JavaScript version: | 1.6 |
---|
More examples
Examples
Find an array "Apple" here:
var a = fruits.lastIndexOf("Apple");
a output:
try it"
Examples
Find the string "Apple" appears from the fourth position in the array:
var a = fruits.lastIndexOf("Apple",4);
a result output:
try it"