4D v17.4

collection.insert( )

Home

 
4D v17.4
collection.insert( )

collection.insert( )  


 

The collection.insert( ) method inserts element at the specified index position in the collection instance and returns the edited collection.

Note: This method modifies the original collection.

In index, pass the position where you want the element to be inserted in the collection.

Warning: Keep in mind that collection elements are numbered from 0.

  • If index > the length of the collection, actual starting index will be set to the length of the collection.
  • If index <0, it is recalculated as index:=index+length (it is considered as the offset from the end of the collection).
  • If the calculated value is negative, index is set to 0.

Any type of element accepted by a collection can be inserted, even another collection.

Example  

 C_COLLECTION($col)
 $col:=New collection("a";"b";"c";"d") //$col=["a","b","c","d"]
 $col.insert(2;"X") //$col=["a","b","X","c","d"]
 $col.insert(-2;"Y") //$col=["a","b","X","Y","c","d"]
 $col.insert(-10;"Hi") //$col=["Hi","a","b","X","Y","c","d"]



See also 

collection.combine( )

 
PROPERTIES 

Product: 4D
Theme: Collections

 
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)