I'm wondering if anyone can confirm whether you can trust ipairs()
to; return all indices in order, for a table that's index-complete but unsorted.
We have code all over our project that clones tables using pairs()
, however any arrays cloned come out unordered. I'm not sure if this is a problem however.
Compare:
A = {10, 20, 30, 40, 50, 60}
to:
B = {[1] = 10, [2] = 20, [3] = 30, [4] = 40, [5] = 50, [6] = 60}
If you loop these with pairs()
, the first one is ordered while the other is not. (On a side note, B
is suddenly sorted if you do a couple of back inserts)
Back to the original question. It seems B
above iterates all values in order using ipairs()
, but is this always guaranteed?
A = {10, 20, 30, 40, 50, 60}
end up ordered when looping withpairs()
. But is not part of the standard. – Babita