a = {}
x = "y"
a[x] = 10 -- put 10 in field "y"
print(a[x]) --> 10 -- value of field "y"
print(a.x) --> nil -- value of field "x" (undefined)
print(a.y) --> 10 -- value of field "y"
local favoritefoods_table = {"hamburger", "spaghetti", "pizza", "potato chips"}
--the table--
for i, v in pairs(favoritefoods_table) do --loop through the table--
print(i) --print the number--
print(v) --print the value--
end
local t = {
"hello",
"how",
"are",
"you"
}
for k,v in pairs(t) do
print("Number: "..k.."Message: "..t)
end
output:
Number: 1 Message: hello
Number: 2 Message: how
Number: 3 Message: are
Number: 4 Message: you