lua tables
snippet in lua

lua tables

user9545

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

table lua

user3984

    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"

lua table

user3157

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

table in lua

user6489

local myTable = {}

lua print all elements table

user1167

local people = {
   {
       name = "Fred",
       address = "16 Long Street",
       phone = "123456"
   },
   {
       name = "Wilma",
       address = "16 Long Street",
       phone = "123456"
   },
   {
       name = "Barney",
       address = "17 Long Street",
       phone = "123457"
   }
}

for index, data in ipairs(people) do
    print(index)

    for key, value in pairs(data) do
        print('\t', key, value)
    end
end

lua tables

user492

local Table = {
	["TABLE_info"] = "TABLE_response"
}

for i, v in pairs(Table) do
	print(v)
end