Typed Array lastIndexOf()
Example
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// The index of the last element with a value of 40
let result = myArr.lastIndexOf(40);
Try it Yourself »
Description
The lastIndexOf()
method returns the last index (position) of a specified value.
The lastIndexOf()
method returns -1 if the value is not found.
The lastIndexOf()
starts at a specified index and searches from right to left
(from the given postion to the beginning of the array).
By defalt the search starts at the last element and ends at the first.
Negative start values counts from the last element (but still searches from right to left).
Syntax
typed-array.lastIndexOf(item, start)
typed-array must be one of the following: Int8ArrayUint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float16Array Float32Array Float64Array BigInt64Array BigUint64Array |
Parameters
Parameter | Description | |
item | Required. The value to search for. |
|
start | Optional. Where to start the search. Default is the last element (array.length-1). Negative start values counts from the last element (but still searches from right to left). |
Return Value
Type | Description |
A number | The position of the specified item. -1 if the item is not found. |
Typed Array Find Methods:
Method | Finds |
---|---|
includes() | Returns true if an element is present in the array |
indexOf() | The index of the first element with a specified value |
lastIndexOf() | The index of the last element with a specified value |
find() | The value of the first element that passes a test |
findIndex() | The index of the first element that passes a test |
findLast() | The value of the last element that passes a test |
findLastIndex() | The index of the last element that passes a test |
JavaScript Typed Arrays
Browser Support
typed-array.lastIndexOf()
is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is fully supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |