up Inquisit Language Reference

indexOf function

Searches the list for a value and returns the index.

Member of

<list>

Syntax

list.name.indexOf(value, start)

Return Type

integer

Parameters

Name Type Description
value value The value to search for.
start integer Optional. The index where the search starts.

Remarks

The indexOf function searches the list for a value and returns the index of the first match. If the value is not found in the list, it returns -1. If the optional start parameter is specified, the search begins at the start position. If start is set to a negative value, the search starts at the given position counting from the end and searches to the end. Otherwise, the search begins with the first item in the list. If there is more than one match in the list, the index of the first match is returned.

Examples

The following code shows how to use function 'indexOf' on list 'myList' to retrieve the first incidence of the item 'Seattle'. By default, the search starts at the first list item at index '0'. The retrieved index is then stored in 'values.index'.

<trial myTrial>
/ onTrialEnd= {values.index = list.myList.indexOf("Seattle");}
</trial>

The following code shows how to use function 'indexOf' on list 'myList' to retrieve the first incidence of the item 'Seattle' starting at list index '5' (list items with index 0-4 are ignored in the search for 'Seattle'). The retrieved index is then stored in 'values.index'.

<trial myTrial>
/ onTrialEnd= {values.index = list.mylist.indexOf("Seattle", 5);}
</trial>

Copyright Millisecond Software, LLC. All rights reserved.