Best way to reset/dupe a table?

If I have a table, lets say:
local table = {"a", "b", "c"}

And I make some modifications to it, maybe I add something to it or remove something.
What’s the best way to “reset” this table to it’s original form? Duping the table beforehand or?

This will create a new table on reset, so make sure you access the table only using the variable.

local tab = {"a","b","c"}

local function resettable()
    tab = {"a","b","c"}
end
1 Like

If you want to just reset the values of the existing table.

local tab = {"a","b","c"}

local deftab = {"a","b","c"}
local function resettable()
    for i in pairs(tab) do tab[i] = nil end
    for i,v in pairs(deftab) do tab[i] = v end
end
1 Like