4D v17.4

collection.extract( )

Home

 
4D v17.4
collection.extract( )

collection.extract( )  


 

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( )

 
PROPERTIES 

Product: 4D
Theme: Collections

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v17)
4D Language Reference ( 4D v17.1)
4D Language Reference ( 4D v17.2)
4D Language Reference ( 4D v17.3)
4D Language Reference ( 4D v17.4)