Table.concat vs table.unpack

I want to know what’s the difference between table.unpack() and table.concat(). They seem to do the same thing, is there a difference? When to use unpack and when to use concat?

1 Like

They’re actually entirely different!

table.unpack takes a table and splits it into a tuple - makes them all individual values seperate of each other, which can be assigned to different variables.

e.g.

local Table = {"Roy_Dev", "PoppyandNeivaarecute", "Albatross"}
local OriginalPoster, SecondPoster, Bird = table.unpack(Table)
print(OriginalPoster) -- "Roy_Dev"
print(SecondPoster) -- "PoppyandNeivaarecute"
print(Bird) -- "Albatross"

table.concat takes a table and turns it into one string, where each element is seperated by a supplied character.

e.g.

local Table = {"Roy_Dev", "PoppyandNeivaarecute", "Albatross"}
print(table.concat(Table, ", ")) -> "Roy_Dev, PoppyandNeivaarecute, Albatross"
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.