Skip to content

JSArray.IndexOf

boxgaming edited this page Jul 25, 2026 · 3 revisions

Returns the first index at which a given element can be found in the array, or -1 if it is not present.

Syntax

result% = JSArray.IndexOf ( a, searchElement [,fromIndex%] )

Parameters

  • The a parameter contains the native Javascript array on which the operation will be performed.
  • The searchElement parameter contains the value used for comparison.
  • The optional fromIndex% specifies the 0-based index of the item to retrieve from the array. Negative integers count back from the last item in the array.

Example

Import JSArray From "lib/lang/array.bas"

Dim colors As Object
colors = JSArray.Create("red", "green", "blue", "orange", "yellow", "white")

Print JSArray.IndexOf(colors, "blue")
Print JSArray.IndexOf(colors, "red")

Output

2
0

See Also

JSArray.Create
JSArray.LastIndexOf
Javascript - Array.indexOf()

Clone this wiki locally