4D v18

collection.fill( )

Home

 
4D v18
collection.fill( )

collection.fill( )  


 

The collection.fill( ) method fills the collection with the specified value, optionally from startFrom index to end index, and returns the resulting collection.

Note: This method modifies the original collection.

  • If the startFrom parameter is omitted, value is set to all collection elements (startFrom=0). If the end parameter is omitted, the value is set to the last element of the collection (end=length).
  • If startFrom < 0, it is recalculated as startFrom:=startFrom+length (it is considered as the offset from the end of the collection). If the calculated value is negative, startFrom is set to 0.
  • If end < 0 , it is recalculated as end:=end+length.
  • If end < startFrom (passed or calculated values), the method does nothing. 

Example  

 C_COLLECTION($c)
 $c:=New collection(1;2;3;"Lemon";Null;"";4;5)
 $c.fill("2") // $c:=[2,2,2,2,2,2,2,2]
 $c.fill("Hello";5) // $c=[2,2,2,2,2,Hello,Hello,Hello]
 $c.fill(0;1;5) // $c=[2,0,0,0,0,Hello,Hello,Hello]
 $c.fill("world";1;-5) //-5+8=3 -> $c=[2,"world","world",0,0,Hello,Hello,Hello]



See also 

collection.resize( )

 
PROPERTIES 

Product: 4D
Theme: Collections

This command can be run in preemptive processes

 
PAGE CONTENTS 
 
HISTORY 

 
ARTICLE USAGE

4D Language Reference ( 4D v18)