Version: v0.7.0 - Beta.  We welcome contributors & feedback.

List.remove

remove($index, $numItems = 1) -> any

Description

Remove an item starting at $index and return its value.

If $index is negative, it counts from the end of the list (the last item is at -1).

If an item does not exist at that index, it returns the default value of the list (e.g. an empty string). If $numItems is greater than one, it returns an empty list.

This function is the opposite of $insert.

$items = ['a', 'b', 'c', 'd', 'e']

$items.remove(1)
//= 'a'

print($items)
//= ['b', 'c', 'd', 'e']

$items.remove(-2)
//= 'd'

print($items)
//= ['b', 'c', 'e']

$items.remove(99)
//= ''

Multiple Items 

If numItems is more than 1, the values will be returned as a List.

If items do not exist at the index, an empty list will be returned.

$items = ['a', 'b', 'c', 'd', 'e']

// Remove the first 2 items
$items.remove(1, 2)
//= ['a', 'b']

print($items)
//= ['c', 'd', 'e']

$items.remove(99, 2)
//= []

See Also