What does # mean?

I am figuring out what does # mean? like for example:

#game.Workspace:GetChildren()

# counts the number of items in an array:

local arrayA = {1, 2, 3, 4}
print(#arrayA) --> 4

local arrayB = {"a", "b", "c", "d", "e"}
print(#arrayB) --> 5
1 Like

The symbol # is used to determine the length of an array.
For example lets say we have a table A. We want to know its length. We use # like:

local A = {1,5,7,3,8,4,0}
print(#A) -- 7 will be the output.

It can be used for many purposes like:

local A = {1,5,7,3,8,4,0}
if #A < 10 and #A > 5 then
    print("The table size is fine.")
end

Kind of nitpicky but the output will be 5. : p

1 Like

Wow thanks! Yo u gave me a very good example and explanation!

No worries, glad the concept has been cleared for you.

You can also do this with a string

local text = "Hello world!"
print(#text) -- 12

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