lastIndexOf

Summary

Returns the last index of the search element in the array.

Signatures

Click on a signature to select it and view its documentation.

Usage

public int lastIndexOf(T searchElement)

Returns

The last index of the search element in the array or -1 if the element could not be found in the array.

Parameters

searchElement

The element to search for.

Description

Returns the last index of the search element in the array. By default, elements are searched by value for primitive data types and by reference otherwise. This behavior can be overridden by implementing the System.ILike<T> interface.

This method does not mutate the array.

This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used.

Examples

Basic Usage
1
2
3
4
5
6
7
8
import System;
 
int[] arr = [ 1, 2, 3, 1 ];
Console.log(arr.indexOf(1));     // 0
Console.log(arr.lastIndexOf(1)); // 3
Console.log(arr.lastIndexOf(2)); // 1
Console.log(arr.lastIndexOf(3)); // 2
Console.log(arr.lastIndexOf(4)); // -1

Share

HTML | BBCode | Direct Link