lua table index code example

Example 1: lua tables

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

Example 2: lua tables

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

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

Example 3: lua empty table

for k,v in pairs(table) do 
 table.remove(table, k)
end

Example 4: how to access an index of a table lua

--How to access something in a table by its index in lua:

local mytable = {"Hi", 6,"Bye"}

--To access it:

mytable[1]
--or
mytable[2]
--or
mytable[3]