## FANDOM

198 Pages

del( tbl, v )

Deletes the first occurrence of a value from a sequence in a table.

tbl
The table.
v
The value to match and remove.

The `del()` function searches a sequence in a table for an element that equals the given value then removes it. All subsequent values in the sequence shift down by one slot to keep the sequence contiguous.

Specifically, `del()` starts with the element at index 1, then increments the index while comparing elements to the given value. When it finds the first element that is equal to the value, it reassigns the indexes of the subsequent values until it reaches an unassigned index (`nil`).

## Examples Edit

```t = {1, 3, 5, 3, 7, 5}
del(t, 3)  -- t = {1, 5, 3, 7, 5}
del(t, 7)  -- t = {1, 5, 3, 5}
del(t, 5)  -- t = {1, 3, 5}

del(t, 9)  -- not found, no changes to t```

The following example demonstrates how equality is used to match elements. A value is only equal to a table if the value is the same table in memory. (Two tables are not equal even if they contain the same elements.)

```x = {'foo'}
t = {}