How to get the size of an array in LUA?

lua

Solution

table.maxn and # look for numeric indices; they won't see your string indices.

As for getting the number of elements in an array with arbitrary indices, I'd probably walk the array using something like:

Count = 0
for Index, Value in pairs( Victim ) do
  Count = Count + 1
end

but I'm an idiot.

Problem

Here is a code: ``` users = {} users["aaa"] = "bbbb"; users["bbb"] = "bbbb"; users["ccc"] = "bbbb"; print("Users count ", table.getn(users)); ``` Why table.getn(users) always returns 0? BTW, #users returns 0 too. So, am I doing something wrong and there is another way to get the amount of elements in the array?

Original source

Related problems