[Home] [Downloads] [Search] [Help/forum]

table.remove

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)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]