table.insert

From ComputerCraft
⧼vector-jumptonavigation⧽ ⧼vector-jumptosearch⧽

table.insert
Function
Syntax
table.insert()
Returns nil
API table
Source Lua (source)

Adds item to the table, at the specified position, or at the end if position is not specified.

ExampleExampleAdd an item to a table
Adds Jens to the table.
Code
local names = {"Markus","John","Tim"}
table.insert(names,"Jens")
print(textutils.serialize(names))
Output
{
    "Markus",
    "John",
    "Tim",
    "Jens",
}
ExampleExampleAdd an item to a table at a certain position
Add Dinnerbone to the table at position 3.
Code
local awesomeMinecraftPeople = {"jeb","Notch","dan200"}
table.insert(awesomeMinecraftPeople, 3, "Dinnerbone")
print(textutils.serialize(awesomeMinecraftPeople))
Output
{
    "jeb",
    "Notch",
    "Dinnerbone",
    "dan200",
}