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

Home

 
4D v19.8
collection.remove( )

collection.remove( ) 


 

collection.remove ( index {; howMany} ) -> Function result 
Parameter Type   Description
index  Longint in Element at which to start removal
howMany  Longint in Number of elements to remove, or 1 element if omitted
Function result  Collection in Original collection without removed element(s)

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
Number: 705242

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)