This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
collection.lastIndexOf( )
|
collection.lastIndexOf ( toSearch {; startFrom} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
toSearch | Expression |
![]() |
The element that is to be searched for within the collection | |||||
startFrom | Longint |
![]() |
Index to start the search at | |||||
Function result | Longint |
![]() |
Index of last occurrence of toSearch in the collection, -1 if not found | |||||
The collection.lastIndexOf( ) method searches the toSearch expression among collection elements and returns the index of the last 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 a reverse search in startFrom.
C_COLLECTION($col)
$col:=Split string("a,b,c,d,e,f,g,h,i,j,e,k,e";",") //$col.length=13
$pos1:=$col.lastIndexOf("e") // returns 12
$pos2:=$col.lastIndexOf("e";6) //returns 4
$pos3:=$col.lastIndexOf("e";15) // returns 12
$pos4:=$col.lastIndexOf("e";-2) // returns 10
$pos5:=$col.lastIndexOf("x") //returns -1
Product: 4D
Theme: Collections
Number:
705247
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)