I’m trying to create a function that can delete all empty subtable in a table. Take for example this table:
local icon = { ["track"] = "Dark Evangelism", ["duration"] = { ["minimum"] = { }, ["maximum"] = { } }, ["stack"] = { ["minimum"] = { ["enabled"] = 1, ["value"] = 5, }, ["maximum"] = { } }, }
I try to delete the empty subtables through these functions:
local function tlengtht(T) --because #table is not precise local count = 0 for \_ in pairs(T) do count = count + 1 end return count end local function clearEmptyTables(t) local visit = {} for k, v in pairs(t) do if type(v) == 'table' then table.insert(visit, v) end end if (tlengtht(t[k]) == 0) then t[k] = nil end for \_, each in ipairs(visit) do clearEmptyTables(each) end end
The second function can eliminate regularly the empty subtables “duration” key (“minimum” and “maximum”), but once you remove these empty subtables I can’t find a way to eliminate key “duration” itself: should become empty once eliminated those values.
Can you help me?