I don't understand the logic behind this
local Tab = {}
Tab[#Tab + 1] = 'Value'
for i,v in pairs(Tab) do
print(i,v)
end
Why do you have to put #Tab number of Tab + 1 why cant you just do Tab + 1
I heard this is also similar to table.insert
I don't understand the logic behind this
local Tab = {}
Tab[#Tab + 1] = 'Value'
for i,v in pairs(Tab) do
print(i,v)
end
Why do you have to put #Tab number of Tab + 1 why cant you just do Tab + 1
I heard this is also similar to table.insert
Putting # in front of a table will return the number of objects it has in it. If you did "Tab + 1" it would be like "{} + 1". But doing #Tab + 1 is like doing "0 + 1" since there are currently no objects in the table!
#TableName gets the number of objects in the table. TableName returns the table.
This discussion is preserved as it was. New answers, comments, and votes are closed.