This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
collection.findIndex( )
|
collection.findIndex ( {startFrom ;} methodName {; param {; param2 ; ... ; paramN}} ) -> Function result | ||||||||
Parameter | Type | Description | ||||||
startFrom | Longint |
![]() |
Index to start the search at | |||||
methodName | Text |
![]() |
Name of the function to call for the find | |||||
param | Expression |
![]() |
Parameter(s) to pass to methodName | |||||
Function result | Longint |
![]() |
Index of first value found, or -1 if not found | |||||
The collection.findIndex( ) method returns the index, in the collection, of the first value for which methodName, applied on each element, returns true. The method returns -1 if no element of the collection was evaluated to true.
Note: This method does not modify the original collection.
By default, collection.findIndex( ) searches in the whole collection. Optionally, you can pass in startFrom the index of element from which to start the search.
In methodName, pass the name of the method to use to evaluate collection elements, along with its parameter(s) in param (optional). methodName can perform any test, using or not the parameter(s). This method receives an Object parameter in $1 and must set $1.result to true for the first element fulfilling the condition.
methodName receives the following parameters:
methodName sets the following parameter(s):
You want to find the position of the first city name within a collection:
C_COLLECTION($c)
C_LONGINT($val2;$val3)
$c:=New collection
$c.push(New object("name";"Cleveland";"zc";35049))
$c.push(New object("name";"Blountsville";"zc";35031))
$c.push(New object("name";"Adger";"zc";35006))
$c.push(New object("name";"Clanton";"zc";35046))
$c.push(New object("name";"Clanton";"zc";35045))
$val2:=$c.findIndex("FindCity";"Clanton") // $val2=3
$val3:=$c.findIndex($val2+1;"FindCity";"Clanton") //$val3=4
The code for the FindCity method is:
C_OBJECT($1)
C_TEXT($2)
$1.result:=$1.value.name=$2
Product: 4D
Theme: Collections
Number:
805256
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)