The ipairs
returns an iterator of ordered key-value pairs. It only iterates from numeric keys, needing to be necessarily sequential, starting from 1 and having no hole between the keys.
This is why your loop doesn’t work, your keys are a string, causing it to return an empty iterator.
Already the pairs
returns an arbitrary order iterator, it works independent of the established key, it can be of any type.
See an example to better understand the differences:
local tbl = { two = 2, one = 1, "alpha", "bravo", [3] = "charlie", [5] = "echo", [6] = "foxtrot" }
print( "pairs:" )
for k, v in pairs( tbl ) do
print( k, v )
end
print( "\nipairs:" )
for k, v in ipairs( tbl ) do
print( k, v )
end
Exit:
pairs:
1 alpha
2 bravo
3 charlie
5 echo
6 foxtrot
one 1
two 2
ipairs:
1 alpha
2 bravo
3 charlie