This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
collection.indexOf( )
|
collection.indexOf ( toSearch {; startFrom} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
toSearch | Expression |
![]() |
Expression to search in the collection | |||||
startFrom | Longint |
![]() |
Index to start the search at | |||||
Function result | Longint |
![]() |
Index of the first occurrence of toSearch in the collection, -1 if not found | |||||
The collection.indexOf( ) method searches the toSearch expression among collection elements and returns the index of the first found occurrence, or -1 if it was not found.
Note: This method does not modify the original collection.
In toSearch, pass the expression to find in the collection. You can pass:
toSearch must match exactly the element to find (the same rules as for the equality operator are applied, see Comparison Operators).
Optionally, you can pass the index of collection from which to start the search in startFrom.
C_COLLECTION($col)
$col:=New collection(1;2;"Henry";5;3;"Albert";6;4;"Alan";5)
$i:=$col.indexOf(3) //$i=4
$i:=$col.indexOf(5;5) //$i=9
$i:=$col.indexOf("al@") //$i=5
$i:=$col.indexOf("Hello") //$i=-1
Product: 4D
Theme: Collections
Number:
805255
Created: 4D v16 R6
4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)