When I put a #
in front of my table name, it errors because of the code in the else
of the if statement
. My table consists of something like this:
local erroringTable = {["s1"]={["id"]="",["desc"]="Description"}}
and when I put a hashtag in front of it,
print(#erroringTable)
is way less than it should be! It's 0! If you the answer, please reply. Thanks!
To count hash table (dictionary), you need to iterate through all keys:
local function Count(table) local count = 0 for _, _ in pairs(table) do count = count + 1 end return count end local erroringTable = {["s1"]={["id"]="",["desc"]="Description"}} print(Count(erroringTable))