4D v17.4

collection.remove( )

Home

 
4D v17.4
collection.remove( )

collection.remove( )  


 

The collection.remove( ) method removes one or more element(s) from the specified index position in the collection and returns the edited collection.

Note: This method modifies the original collection.

In index, pass the position where you want the element to be removed from the collection. Warning: Keep in mind that collection elements are numbered from 0. If index is greater than 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 < 0, index is set to 0.
  • If the calculated value > the length of the collection, index is set to the length.

In howMany, pass the number of elements to remove from index. If howMany is not specified, then one element is removed.

If you try to remove an element from an empty collection, the method does nothing (no error is generated).

Example  

 C_COLLECTION($col)
 $col:=New collection("a";"b";"c";"d";"e";"f";"g";"h")
 $col.remove(3) // $col=["a","b","c","e","f","g","h"]
 $col.remove(3;2) // $col=["a","b","c","g","h"]
 $col.remove(-8;1) // $col=["b","c","g","h"]
 $col.remove(-3;1) // $col=["b","g","h"]



See also 

collection.clear( )

 
PROPERTIES 

Product: 4D
Theme: Collections

This command can be run in preemptive processes

 
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)