Summary
Removes an item from a numerically-keyed table
Prototype
val = table.remove (t, pos)
Description
Removes the element at position 'pos' from the table, returning the value of the removed element.
If 'pos' is omitted it defaults to the end of the table (n), thus removing the last element.
t = { "the", "quick", "brown", "fox" }
print (table.remove (t, 3))
table.foreachi (t, print)
-->
brown
1 the
2 quick
3 fox
The Lua authors recommend using this method for removing from the end of a table nowadays:
t [#t] = nil -- remove last entry
Note that for other keys (eg. strings) you simply assign nil to the element to remove it. For example:
t = {}
t.foo = "bar" -- add item
t.foo = nil -- remove item
See Also ...
Lua functions
table.concat - Concatenates table items together into a string
table.foreach - Applies a function to each item in a table
table.foreachi - Applies a function to each item in a numerically-keyed table
table.getn - Returns the size of a numerically-keyed table
table.insert - Inserts a new item into a numerically-keyed table
table.maxn - Returns the highest numeric key in the table
table.setn - Sets the size of a table (obsolete)
table.sort - Sorts a table
Topics
Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua LPEG library
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting
Scripting callbacks - plugins
(Help topic: lua=table.remove)