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.

Usage

public int indexOf(T searchElement)

Returns

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.

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.

Examples

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

Share

HTML | BBCode | Direct Link