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

Home

 
4D v19.8
collection.pop( )

collection.pop( ) 


 

collection.pop () -> Function result 
Parameter Type   Description
Function result  Expression in Last element of collection

The collection.pop( ) method removes the last element from the collection and returns it as the function result.

Note: This method modifies the original collection.

When applied to an empty collection, collection.pop( ) returns undefined.

Example  

collection.pop( ), used in conjunction with collection.push( ), can be used to implement a first-in, last-out stack feature:

 C_COLLECTION($stack)
 $stack:=New collection //$stack=[]
 $stack.push(1;2) //$stack=[1,2]
 $stack.pop() //$stack=[1]  Returns 2
 $stack.push(New collection(4;5)) //$stack=[[1,[4,5]]
 $stack.pop() //$stack=[1]  Returns [4,5]
 $stack.pop() //$stack=[]  Returns 1



See also 

collection.push( )
collection.unshift( )

 
PROPERTIES 

Product: 4D
Theme: Collections
Number: 805253

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)