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

Home

 
4D v19.8
collection.push( )

collection.push( ) 


 

collection.push ( element {; element2 ; ... ; elementN} ) -> Function result 
Parameter Type   Description
element  Expression in Element(s) to add to the collection
Function result  Collection in Original collection containing added elements

The collection.push( ) method appends one or more element(s) to the end of the collection instance and returns the edited collection.

Note: This method modifies the original collection.

 C_COLLECTION($col)
 $col:=New collection(1;2) //$col=[1,2]
 $col.push(3) //$col=[1,2,3]
 $col.push(6;New object("firstname";"John";"lastname";"Smith"))
  //$col=[1,2,3,6,{firstname:John,lastname:Smith}

You want to sort the resutling collection:

 C_COLLECTION($col;$sortedCol)
 $col:=New collection(5;3;9) //$col=[5,3,9]
 $sortedCol:=$col.push(7;50).sort()
  //$col=[5,3,9,7,50]
  //$sortedCol=[3,5,7,9,50]



See also 

collection.pop( )
collection.shift( )

 
PROPERTIES 

Product: 4D
Theme: Collections
Number: 705255

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)