Arrays

  • Arrays are sequential tables
    • without nils at intermediate locations
  • Arrays are made up indexing tables by integers
  • Customarily arrays in Lua start at 1
    • You can start them at any integer index
  • The length hash (#) works with arrays

array1 = {}; for i=1, 10 do array1[i] = "value" .. i end for i=1, 10 do print(array1[i]) end print("\n\n\n") -- using a constructor to initialize and array array2 = {"value1", "value2", "value3", "value4",} for i=1, #array2 do print(array2[i]) end