How to nil every object in a table?

How to nil every object in a table? Should I use a loop or is there a quicker way to have everything including the table to nil.

for i,v in pairs(YOURTABLE)
v = nil
end

or

for c = 1,#yourtable do
yourtable[c] = nil
end

Use

table.clear(yourTable)
1 Like
local tables = {"a", "b", "c", "d", "e"}
tables = {} --overrides previous table with a new empty one
table.clear(tables) --clears a table (essentially the same as the previous line)

for _, instance in ipairs(workspace:GetDescendants()) do
	instance:Destroy()
end

for _, instance in ipairs(workspace:GetDescendants()) do
	instance.Parent = nil
end

for _, instance in ipairs(workspace:GetDescendants()) do
	game.Debris:AddItem(instance, 0.015)
end

Depends what you’re referring to, for a table of primitive values/references to instances if you just want to empty/clear the table then you can override the existing table by assigning to its storing variable an empty table value or by calling table.clear() and passing the variable of which the table value is stored as an argument to the table.clear() function. If you want to nil/destroy every instance in an instance then you can use any of the three loops provided, the former is the one most frequently used.