I never got how people used ipairs, pairs, or #. It's like... I just don't get it.
COMMUNITY QUESTION
?Can someone help explain these things:
1 answer
ipairs and pairs are simply built in functions that iterate through arrays/tables. They are there for convenience so you don't have to write your own. These are used in generic for loops.
Usage example:
local array = {
[index] = value,
[2] = "b",
["Apple"] = "Banana"
}
for index, value in ipairs(array) do
print(index, value)
end
--[[Output
index output
2 b
Apple Banana
--]]
# is used to retrieve the number of items in an array/table. These are commonly used in basic for loops.
Usage Example:
local array = {1, "Apple", game.Workspace}
for i = 1, #array do
print(array[i])
end
--[[Output
1
Apple
Workspace
--]]
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
In your second example the output would actually show "1, Apple, Workspace" For more on pairs versus ipairs, https://scriptinghelpers.org/questions/4/whats-the-difference-between-pairs-and-ipairs
Now how would you use those to make gui's and stuff?
Whoops, thanks Perci1!