indexOf Summary Returns the first index of the search element in the array. Signatures Click on a signature to select it and view its documentation. public int indexOf(T searchElement) public int indexOf(T searchElement, int startingIndex) Usage public int indexOf(T searchElement) public int indexOf(T searchElement, int startingIndex) Returns The first index of the search element in the array or -1 if the element could not be found in the array. The first 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. startingIndex The zero-based index to begin the search from. This argument can be negative to specify an index relative to the end of the array. Description Returns the first 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 first index of the search element in the array with the search beginning at the specified starting 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 1234567import System; int[] arr = [ 1, 2, 3 ];Console.log(arr.indexOf(1)); // 0Console.log(arr.indexOf(2)); // 1Console.log(arr.indexOf(3)); // 2Console.log(arr.indexOf(4)); // -1 Basic Usage 12345import System; int[] arr = [ 1, 2, 3 ];Console.log(arr.indexOf(2, 0)); // 1Console.log(arr.indexOf(2, 3)); // -1 Search beginning from the last element 1234import System; int[] arr = [ 1, 2, 3, 1 ];Console.log(arr.indexOf(1, -1)); // 3 Share HTML | BBCode | Direct Link