Finds the last position holding a value and returns it, or -1 when the value is not in the array.
The search starts at the final item and walks backward, so when a value appears more than once the highest index comes back.
A result of -1 means the value is absent; any other result is a usable index for array.get() and array.set().
Syntax
array.lastindexof(id: any array type, value: series <type of the array's elements>) -> series int
array.lastindexof(value: series <type of the array's elements>) -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | any array type | required | The array to search from the back for the value. |
| value | series <type of the array's elements> | required | The item to look for. It has to match the type of the array's items. |
Returns
series int: The index of the last match, or -1.
Remarks
- The forward search is
array.indexof(). When the array is sorted,array.binary_search_rightmost()finds the last copy faster.
Example
//@version=6
indicator("array.lastindexof: low age", overlay = false)
var lows = array.new_float()
array.push(lows, low)
if array.size(lows) > 20
array.shift(lows)
idx = array.lastindexof(lows, array.min(lows))
plot(array.size(lows) - 1 - idx, "Bars since lowest low")See also
Runs on Sidechair