Search code examples
dictionaryluacall

Is there a way to iterate over a table value in Lua?


I have the following table in Lua:

local a = {orszag = {"Ausztria", "Albánia", "Azerbajdzsán"}, varos = {"Ankara", "Amszterdam", "Antwerpen"}, fiu = {"Arnold", "Andor", "Albert"}, lany = {"Anna", "Anasztázia", "Amanda"}}

I would like to do the following:

for i in a["orszag"] do etc. (for example compare all the words in the value to the user input)

But when I do so I get the following: attempt to call a table value.

So I know, it works in python for example, but is it possible somehow to do this in Lua as well?


Solution

  • Use

    for k,v in pairs(a["orszag"]) do