TypedArray lastIndexof() JavaScript

The Javascript TypedArray lastIndexof() method is used to get the last position of a value. It will return -1 if the specified value is not found in the array.

Syntax:

array.lastIndexOf(value, start)

Parameters: value: It represents the current element’s value. start: It represents the index position from where to start the search. The default is array size – 1.

Returns: It returns the index of the last position of the specified element. It will return -1 if a specified element is not found in the array.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">   
var Jewels = "DIAMOND-GOLD";
document.write(Jewels.lastIndexOf("O"));  
</script>
</body>
</html>

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript"> 
const testArray = new Uint8Array([45, 67, 12, 12, 12, 11]);
 
document.write(testArray.lastIndexOf(12, 5));
document.write("</br>");
 
document.write(testArray.lastIndexOf(12, 3));
 
</script>
</body>
</html>
Please follow and like us:
Content Protection by DMCA.com