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

Home

 
4D v19.8
collection.resize( )

collection.resize( ) 


 

collection.resize ( size {; defaultValue} ) -> Function result 
Parameter Type   Description
size  Longint in New size of the collection
defaultValue  Number, Text, Object, Collection, Date, Boolean in Default value to fill new elements
Function result  Collection in Resized original collection

The collection.resize( ) method sets the collection length to the specified new size and returns the resized collection.

Note: This method modifies the original collection.

  • If size < collection length, exceeding elements are removed from the collection.
  • If size > collection length, the collection length is increased to size.
    By default, new elements are filled will null values. You can specify the value to fill in added elements using the defaultValue parameter.

Example  

 C_COLLECTION($c)
 $c:=New collection
 $c.resize(10) // $c=[null,null,null,null,null,null,null,null,null,null]
 
 $c:=New collection
 $c.resize(10;0) // $c=[0,0,0,0,0,0,0,0,0,0]
 
 $c:=New collection(1;2;3;4;5)
 $c.resize(10;New object("name";"X")) //$c=[1,2,3,4,5,{name:X},{name:X},{name:X},{name:X},{name:X}]
 
 $c:=New collection(1;2;3;4;5)
 $c.resize(2) //$c=[1,2]



See also 

collection.fill( )
collection.length

 
PROPERTIES 

Product: 4D
Theme: Collections
Number: 705243

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)