Grammar
var index = Array.lastindexof (searchelement[, Fromindex]);
Parameter description
Searchelement: Elements to search for
Fromindex: The location at which to start the search, the default length of the array, in which case, all the elements of the element will be searched. If the value passed in is greater than or equal to the range of the array (length), the entire array is searched, and if the passed-in value is less than 0, it returns-1, in which case the search operation will not be executed. The search is in the opposite direction.
Function description
Compares the absolute consistency (= = =) of each element of the searchelement and array, and returns the index of the current element when an element meets the criteria. If it is not found, return directly to-1.
In browsers that do not support this property, you can use the following code:
| The code is as follows |
Copy Code |
<script language= "JavaScript" type= "Text/javascript" >
Description: LastIndexOf () method for Javascript Array
if (! ARRAY.PROTOTYPE.LASTINDEXOF) { Array.prototype.lastIndexOf = function (ELT/*, from*/) { var len = this.length;
var from = number (arguments[1]); if (isNaN (from)) { from = len-1; } Else { From = (From < 0) ? Math.ceil (from) : Math.floor (from); if (from < 0) from + = Len; else if (from >= len) from = len-1; } for (; from >-1; from--) { If (from, this && this[from] = = ELT) return from; } return-1; }; } </script> |