Answers for "lua hash table length"

Lua
2

making an array lua

local Table = {"A", "B", "C", 1, 2, 3} -- Tables can have multiple value types.
print(Table[3]) -- Lua table indices start at 1 rather than 0.
Posted by: Guest on May-17-2020
0

lua hash table length

-- there is no way to achieve this other than to create your own function.
-- using #table ("#" is shorthand for table.getn(table)) won't factor in key names.
function table_length(t)
    local z = 0
    for i,v in pairs(t) do z = z + 1 end
    return z
end
Posted by: Guest on December-11-2020

Browse Popular Code Answers by Language