This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v19.8
collection.find( )
|
collection.find ( {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 |
![]() |
First value found, or Undefined if not found | ||||||
The collection.find( ) method returns the first value in the collection for which methodName, applied on each element, returns true.
Note: This method does not modify the original collection.
By default, collection.find( ) 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, with or without 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 get the first element with a length smaller than 5:
C_COLLECTION($col)
$col:=New collection("hello";"world";4;"red horse";"tim";"san jose")
$value:=$col.find("LengthLessThan";5) //$value="tim"
The code for LengthLessThan method is:
C_OBJECT($1)
C_LONGINT($2)
If(Value type($1.value)=Is text)
$1.result:=(Length($1.value))<$2
End if
You want to find a city name within a collection:
C_COLLECTION($c)
$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))
$c2:=$c.find("FindCity";"Clanton") //$c2={name:Clanton,zc:35046}
The code for the FindCity method is:
C_OBJECT($1)
C_TEXT($2)
$1.result:=$1.value.name=$2 //name is a property name of objects in the collection
Product: 4D
Theme: Collections
Number:
805258
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)