A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/Array/lastIndexOf below:

lastIndexOf · WebPlatform Docs

lastIndexOf Summary

Returns the index of the last occurrence of a specified value in an array.

Syntax
lastIndexOf( searchElement [, fromIndex ])
searchElement
Required. The value to locate in array1.
fromIndex
Optional. The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.
Return Value

The index of the last occurrence of searchElement in the array, or -1 if searchElement is not found.

Examples

The following examples illustrate the use of the lastIndexOf method.


 var ar = ["ab", "cd", "ef", "ab", "cd"];

 
 document.write(ar.lastIndexOf("cd") + "<br/>");

 

 
 document.write(ar.lastIndexOf("cd", 2) + "<br/>");

 

 
 document.write(ar.lastIndexOf("gh")+ "<br/>");

 

 
 
 
 document.write(ar.lastIndexOf("ab", -3) + "<br/>");
 
Remarks

The lastIndexOf method searches an array for a specified value. The method returns the index of the last occurrence, or -1 if the specified value is not found.

The search occurs in descending index order (last member first). To search in ascending order, use the indexOf Method (Array).

The array elements are compared to the searchElement value by strict equality, similar to the comparison made by the === operator. For more information, see Comparison Operators.

The optional fromIndex argument specifies the array index at which to begin the search. If fromIndex is greater than or equal to the array length, the whole array is searched. If fromIndex is negative, the search starts at the array length plus fromIndex. If the computed index is less than 0, -1 is returned.

See also Specification

[15.4.4.15 Array.prototype.lastIndexOf ( searchElement , fromIndex )] ECMAScript® Language Specification Standard ECMA-262 5.1 Edition / June 2011

Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4