JavaScript Array lastIndexOf()

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 a required parameter and represents the element that has to be searched.
index: It is an optional parameter and represents the index position from where the 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>