table.insert

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

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

table.insert
Function
Syntax
table.insert(
  • table : table
  • position? : number
  • item : any
)

Returns nil
API table
Source Lua (source)
This article is issued from Computercraft. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.