Garry's Mod Wiki

table.remove

  any table.remove( table tbl, number index = #tbl )

Description

Removes a value from a table and shifts any other values down to fill the gap.

Does nothing if index is less than 1 or greater than #tbl

Arguments

1 table tbl
The table to remove the value from.
2 number index = #tbl
The index of the value to remove.

Returns

1 any
The value that was removed.

Example

Demonstrates the use of this function.

sentence = { "hello", "there", "my", "name", "is", "Player1" } print( table.remove( sentence ) ) -- Using no second arg removes the last value print( table.remove( sentence, 2 ) ) PrintTable( sentence )
Output:
Player1 there 1 = hello 2 = my 3 = name 4 = is