Loading

REMOVE

maps lists

Removes an entry from a MAP or from a LIST.

The REMOVE function consumes a list (or a map) and a index (or a key), then remove the entry. It lets the input on the stack and puts the removed item on top of the stack. As a result, the input map or list is modified and the map or list left on top of the stack is not a copy.

If the index is out of bound, the returned value is NULL and the list or array is unmodified. If the key does not exist in the map, it returns null as the removed entry.

Since 2.1, the index can be negative. In this case the effective index is index + size of the LIST or GTS.

Since 2.7, REMOVE can be called on a GTS.

REMOVE is available since version 1.0.0.

See also

Signatures

Examples

//LIST examples [ 'apple' 'banana' 'orange' ] 'mylist' STORE $mylist 1 REMOVE //$mylist 2 REMOVE //try to uncomment this line (error!) '' //remove two first items [ 'item01' 'item02' 'item03' 'item04' 'item05' ] 0 REMOVE SWAP 0 REMOVE SWAP '' //remove the last item [ 'item01' 'item02' 'item03' 'item04' 'item05' ] DUP //SIZE will replace the TOP of the stack SIZE 1 - // list size - 1 REMOVE DROP //don t want to keep 'item05' on the TOP of the stack
{ 'label0' 42 'label1' 'foo' 'label2' true } 'mymap' STORE $mymap 'label1' REMOVE $mymap 'notalabel' REMOVE