JavaScript Array lastIndexOf() method

The JavaScript array lastIndexOf() method is used to search the specified element in the given array and returns the index of the last match.

Syntax:

array.lastIndexOf (element,index)

Parameters:
element: It is required parameter and represent the element which have to be searched.
index: It is optional parameter and represent the index position from where search starts.

Returns:
Index of the last match for a specific element.

Example:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>  
var a = ["GOLD","RUBY","DIAMOND","RUBY","PLATINUM"]	 
var result= a.lastIndexOf("RUBY");  
document.writeln(result);
</script>  
</body>
</html>

Output:

3
Please Share