This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
4D v20 R7
COLLECTION TO ARRAY
|
COLLECTION TO ARRAY ( collection ; array {; propertyName}{; array2 ; propertyName2 ; ... ; arrayN ; propertyNameN} ) | ||||||||
Parameter | Type | Description | ||||||
collection | Collection |
![]() |
Collection to copy in array(s) | |||||
array | Array |
![]() |
Array to receive the elements of the collection; if propertyName passed, array to receive the values of propertyName in the collection | |||||
propertyName | Text |
![]() |
Object property name whose values to copy in array ("" for all elements) | |||||
The COLLECTION TO ARRAY command fills one or more array(s) with elements or propertyName values from the collection into the array(s).
This command can work with a collection that contains values or a collection that contains objects, in which case the propertyName parameter(s) are mandatory.
In all cases, 4D converts the collection elements or values according to the type of array (if necessary). Conversion rules are detailed in the Type conversions between collections and 4D arrays page.
You want to copy a collection of strings in a text array:
C_COLLECTION($fruits)
$fruits:=New collection("Orange";"Banana";"Apple";"Grape")
ARRAY TEXT($artFruits;0)
COLLECTION TO ARRAY($fruits;$artFruits)
//$artFruits{1}="Orange"
//$artFruits{2}="Banana"
//...
You want to copy different property values from a collection of objects in different arrays:
C_COLLECTION($col)
$col:=New collection
ARRAY TEXT($city;0)
ARRAY LONGINT($zipCode;0)
$col.push(New object("name";"Cleveland";"zc";35049))
$col.push(New object("name";"Blountsville";"zc";35031))
$col.push(New object("name";"Adger";"zc";35006))
$col.push(New object("name";"Clanton";"zc";35046))
$col.push(New object("name";"Shelby";"zc";35143))
COLLECTION TO ARRAY($col;$city;"name";$zipCode;"zc")
//$city{1}="Cleveland", $zipCode{1}=35049
//$city{2}="Blountsville", $zipCode{2}=35031
//...
ARRAY TO COLLECTION
Type conversions between collections and 4D arrays
Product: 4D
Theme: Collections
Number:
1562
Created: 4D v16 R6
4D Language Reference ( 4D v20 R7)