TypedArray.lastIndexOf() function in JavaScript


The lastIndexOf() function of the TypedArray object accepts a value and verifies whether the typed array contains the specified element. If so, this function returns the index of the array at which the specified element found, if the element occurred multiple timed this function returns the last index among them. If the array doesn’t contain the specified element the indexOf() function returns -1.

Syntax

Its Syntax is as follows

typedArray.lastIndexOf(50)

Example

 Live Demo

<html>
<head>
   <title>JavaScript Array every Method</title>
</head>
<body>
   <script type="text/javascript">
      var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55, 66, 97, 66 ]);
      document.write("Contents of the typed array: "+int32View);
      document.write("<br>");
      var contains = int32View.lastIndexOf(66);
      document.write("Specified element occurred at the index: "+contains);
   </script>
</body>
</html>

Output

Contents of the typed array: 21,19,65,21,14,66,87,55,66,97,66
Specified element occurred at the index: 10

Updated on: 25-Jun-2020

20 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements