This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
collection.extract( )

collection.extract( ) 


 

collection.extract ( propertyPath {; targetPath}{; propertyPath2 ; targetPath2 ; ... ; propertyPathN ; targetPathN}{; option}) -> Function result 
Parameter Type   Description
propertyPath  Text in Object property path whose values must be extracted to the new collection
targetPath  Text in Target property path or property name
option  Longint in ck keep null: include null properties in the returned collection (ignored by default). Parameter ignored if targetPath passed.
Function result  Collection in New collection containing extracted values

The collection.extract( ) method creates and returns a new collection containing propertyPath values extracted from the original collection of objects.

Note: This method does not modify the original collection.

The contents of the returned collection depends on the targetPath parameter:

  • If the targetPath parameter is omitted, collection.extract( ) populates the new collection with the propertyPath values of the original collection.
    By default, elements for which propertyPath is null or undefined are ignored in the resulting collection. You can pass the ck keep null constant in the option parameter to include these values as null elements in the returned collection.
  • If one or more targetPath parameter(s) are passed, collection.extract( ) populates the new collection with the propertyPath properties and each element of the new collection is an object with targetPath properties filled with the corresponding propertyPath properties. Null values are kept (option parameter is ignored with this syntax).

 C_COLLECTION($c)
 $c:=New collection
 $c.push(New object("name";"Cleveland"))
 $c.push(New object("zip";5321))
 $c.push(New object("name";"Blountsville"))
 $c.push(42)
 $c2:=$c.extract("name") // $c2=[Cleveland,Blountsville]
 $c2:=$c.extract("name";ck keep null//$c2=[Cleveland,null,Blountsville,null]

 C_COLLECTION($c)
 $c:=New collection
 $c.push(New object("zc";35060))
 $c.push(New object("name";Null;"zc";35049))
 $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.extract("name";"City") //$c2=[{City:null},{City:Cleveland},{City:Blountsville},{City:Adger},{City:Clanton},{City:Clanton}]
 $c2:=$c.extract("name";"City";"zc";"Zip") //$c2=[{Zip:35060},{City:null,Zip:35049},{City:Cleveland,Zip:35049},{City:Blountsville,Zip:35031},{City:Adger,Zip:35006},{City:Clanton,Zip:35046},{City:Clanton,Zip:35045}]



See also 

collection.map( )
entitySelection.extract( )

 
PROPERTIES 

Product: 4D
Theme: Collections
Number: 805251

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v16 R6

 
ARTICLE USAGE

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)