None of that is correct.
ipairs iterates over arrays (1 = âhiâ, 2 = âappleâ)
pairs iterates over arrays and dictionaries both (test = âhiâ, example = âappleâ)
next is the same as pairs as far as you are concerned, but specifically it gets the next entry in the table.
next({test = âhiâ, example = âappleâ}, test) â example, apple
next is a function, pairs is a function, ipairs is a function. None of them are made by Roblox, they exist in vanilla lua.
pairs also returns next if you care.
local function pairs(t)
return next, t
end
Thatâs pretty much an exact copy of pairs.
Edit: Also, from PiL, this is a replacement for ipairs. I think ipairs (like next) is handled in C-side so it is more efficient to use ipairs than this replacement, but this will do the same thing otherwise.
function iter (a, i)
i = i + 1
local v = a[i]
if v then
return i, v
end
end
function ipairs (a)
return iter, a, 0
end
next
has no replacement, and if you want to get a value in a dictionary without knowing an exact key, you must use it.
Edit 2 since I canât proofread and come up with more than one thought at a time:
you can use the âiterâ function I shared the same as you can next
for i, v in next, t do
for i, v in iter, t do
the difference being that next
is still irreplaceable and iter
doesnât have the capability to iterate over string keys, only integral keys. In other words, ipairs and PiLâs iter
function will only work on tables that look like this
{"test", "seven", "red car", game.Workspace}
next and pairs will both work on tables that look like this as well as the table above.
{brand = "Mazda", color = "White", milage = 100}