Type Function Library table.* Return value (varies) Revision Release 2024.3703 Keywords table, array See also table.insert()
Removes from table the element at position pos
, shifting down other elements to close the space, if necessary. Returns the value of the removed element.
table.remove()
may affect performance because it has to shuffle all of the elements in the array (following the one being removed) down by one. Thus, it should not be used in
table.remove( t ) table.remove( t, pos )
Table. The table from which to remove.
Number. Position of the element to remove. Its default value is the length of the table, so table.remove(t)
removes the last element of t
.
local exampleTable = { 1,1,2,3,5,8,13 } print( table.maxn(exampleTable) ) --> 7 print( table.remove(exampleTable,4) ) --> 3 print( table.maxn(exampleTable) ) --> 6 print( table.remove(exampleTable) ) --> 13
local exampleTable = { 1,1,2,3,5,8,13 } for i = #exampleTable,1,-1 do table.remove(exampleTable,i) end