delete()/deleteElement()

 

The delete() method removes all the specified array elements within the given range or at the given position. This method accepts form 1 to 2 parameters:

 

array_variable.delete(first [,last])

 

Both arguments are integer expressions which indicate the index of the array elements. If only one argument is given, the array element with the index corresponding to this argument will be deleted.

The deleteElement() method removes only one array element and needs the index of the element as the argument:

 

array_variable.deleteElement(element_index)

 

When elements are deleted from a dynamic array, the array size is reduced by the number of the deleted elements.

 

DEFINE ar DYNAMIC ARRAY OF CHAR(15)

...

FOR i = 1 TO 100                 #the array has 100 elements

   LET ar[i]="element "||i

END FOR

 

CALL ar.delete(50)               #the 50th element is deleted and the array size is                               #99

CALL ar.delete(10,30)            #20 elementa are deleted and the array size is 79