I'm attempting to iterate through an array, like the following:
local array ={ ['hi'] = "Hello"; ['test'] = "Greetings"; }
and print out the key and value like:
hi = Hello
My current code is:
for i,v in ipairs(array) do print(i.." = "..v) end
ipairs
specifically only iterates through integer numerical indices. What you want to use is pairs
:
for i,v in pairs(array)do print(i.." = "..v) end
well, what I see happening is you are putting tables in arrays and the tables are something, idk your thing is hard to read. What I would do though is.
local array = { Hi = "Hello", -- hi is just a codename for Hello like print(array.Hi) would print out Hello Bye = "Good-Bye" } for i,v in pairs(array) do print(v) end