local VotingUIs = { script.Parent:WaitForChild("Classic"), script.Parent:WaitForChild("Combat"), script.Parent:WaitForChild("Double Killers") } for i, v in ipairs(VotingUIs) do print(v) end
using both pairs and ipairs work here, but i want to know which is better to use in this situation.
even though the forum says that ipairs() is for arrays, pairs() seem to work for arrays as well
Truthfully, it boils down to personal choice here. Both in pairs
and in ipairs
will work for an array, but only in pairs
works for dictionaries.
If you want something faster you could use a for i = 1,n
loop and index the table using that like so:
local table = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } for i = 1, #table, 1 do print(table[i]) end
Again, they accomplish the same thing it all boils down to aesthetic.