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. public int lastIndexOf(T searchElement) public int lastIndexOf(T searchElement, int endingIndex) Usage public int lastIndexOf(T searchElement) public int lastIndexOf(T searchElement, int endingIndex) Returns The last index of the search element in the array or -1 if the element could not be found in the array. 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. Parameters searchElement The element to search for. endingIndex The zero-based index to limit and end the search at. This argument can be negative to specify an index relative to the end of the array. 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. Returns the last index of the search element in the array until the specified ending index. 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 12345678import System; int[] arr = [ 1, 2, 3, 1 ];Console.log(arr.indexOf(1)); // 0Console.log(arr.lastIndexOf(1)); // 3Console.log(arr.lastIndexOf(2)); // 1Console.log(arr.lastIndexOf(3)); // 2Console.log(arr.lastIndexOf(4)); // -1 Basic Usage 1234567import System; int[] arr = [ 1, 2, 3, 1 ];Console.log(arr.indexOf(1)); // 0Console.log(arr.lastIndexOf(1)); // 3Console.log(arr.lastIndexOf(1, 1)); // 0Console.log(arr.lastIndexOf(1, 3)); // 3 Search until the penultimate element 1234import System; int[] arr = [ 1, 2, 3, 1 ];Console.log(arr.lastIndexOf(1, -2)); // 0 Share HTML | BBCode | Direct Link