Pairs() or ipairs(). Which is better?

Which is one is better? pairs() or ipairs()?

And what is the difference between them?

1 Like

It depends on the usage

Simply:

pairs() is used for Dictionaries
ipairs() is used for Arrays

1 Like

ipairs() is better as it stops yielding if it reaches nil in a table

3 Likes

Honestly, neither doesn’t have to be used on Roblox’s Luau (it’s not required anymore).

Luau will automatically determine whether or not a table will require ipairs() for perfect numerical tables (all indices numerical, no skipping of index) or pairs() (for dictionaries and everything else).

If were’ talking about vanilla Lua, ipairs and pairs still have to be used.

1 Like

Pretty sure it just uses pairs, it doesn’t determine automatically.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.