Unfortunately table.concat only works with arrays. You’ll have to do a bit of a workaround to get the result you’re hoping for.
local items = {
["apple"] = 5,
["pen"] = 3,
["juice"] = 4,
}
local function Count(tab)
local num = 0
for i in next, tab do
num = num + 1
end
return num
end
local function ConcatTab(tab, del)
local str = ""
local num = Count(tab)
local temp = 1
for i, v in pairs(tab) do
if temp ~= num do
str = str .. i .. " " .. v .. del
elseif i == #tab then
str = str .. i .. " " .. v
end
temp = temp + 1
end
return str
end
print("[", ConcatTab(items, ", "), "]")
If you need any kinda explanation about any of this, don’t hesitate to let me know. Peace.