Get Item Index
Verb: indexOf
Gets the index of an item in a given List. The index corresponds to the item's position on the list.
Collections are enumerable data structures that can be accessed using indexes and keys.
Syntax
indexOf --value(Variant) --collection(List<Variant>) (Numeric)=value
Inputs
Script | Designer | Required | AcceptedTypes | Description |
---|---|---|---|---|
--value | Item | Required | Any | Item of which the index should be obtained in the List. |
--collection | List | Required | List<Any> | List from which the desired item's index should be obtained. |
Outputs
Script | Designer | AcceptedTypes | Description |
---|---|---|---|
value | Index | Number | Index of the item. |
Example
Gets the index of the item inserted in the Item parameter and stores it in a variable.
defVar --name namesCollection --type List --innertype String --value "[Ana,Mary,Lucas,Victor]"
defVar --name itemIndex --type Numeric
indexOf --value Lucas --collection "${namesCollection}" itemIndex=value
logMessage --message "${itemIndex}" --type "Info"
//The result obtained in ${itemIndex} is: 3.