Skip to content

Latest commit

 

History

History
20 lines (8 loc) · 512 Bytes

Tables as Arrays in Lua.md

File metadata and controls

20 lines (8 loc) · 512 Bytes

Tables as Arrays in Lua

l

Lua's tables can be used to represent arrays, with integer keys and consecutive indices starting at 1. Here's an example:

local my_array = {"apple", "banana", "cherry", "durian"}

for i = 1, #my_array do

print(my_array[i])

end

In this example, my_array is an array of strings. The for i = 1, #my_array do line loops over each element of the array using its index.