Lists

Lists, often also called arrays, are data structures that organize elements such as values by index.

-- initialize a table with values

local x = { "a", "b" }
-- access values stored in the table

print(x[1]) -- a
print(x[2]) -- b
-- update a value in the table

x[2] = "c"

print(x[1]) -- a
print(x[2]) -- c
-- add a value to the end of the table

table.insert(x, "d")

print(x[1]) -- a
print(x[2]) -- c
print(x[3]) -- d
-- remove a value from the table

table.remove(x, 2)

print(x[1]) -- a
print(x[2]) -- d
print(x[3]) -- nil