Code
lua
-- Array (1-indexed!)
local fruits = {"apple", "banana", "cherry"}
print(fruits[1]) -- "apple" (not fruits[0])
print(#fruits) -- 3 (length)
-- Map / dictionary
local person = {name = "Alice", age = 30, city = "NYC"}
print(person.name) -- "Alice"
print(person["age"]) -- 30
-- Mixed
local mixed = {10, 20, 30, name = "Bob", [100] = "indexed"}
print(mixed[1]) -- 10
print(mixed.name) -- "Bob"
print(mixed[100]) -- "indexed"
-- Iterate array
for i, v in ipairs(fruits) do
print(i, v)
end
-- Iterate map (no order guarantee)
for k, v in pairs(person) do
print(k, v)
end
-- Insert / remove
table.insert(fruits, "date")
table.remove(fruits, 1) -- removes "apple"