Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to all remove in a table?

Asked by 6 years ago

Is it possible to remove all in a table without remove the table?

1 answer

Log in to vote
0
Answered by 6 years ago

Yes, it’s possible to remove everything in a table without destroying the table itself (is that even possible?). It just takes a simple for loop and table.remove to accomplish this.

Here is an example :

local cleanthistableplz = {"junk", "more junk", 0572859285, 'Wafflez'}

for i = 0, #cleanthistableplz, 1 do
     table.remove(cleanthistableplz, i)
end

So as you can see, I have a table full of strings and stuff. With the for loop, the "i" value goes up based on the number of things in the table and removes them all using table.remove.

Hoped this helped!

I actually don’t know a lot about tables at the moment since I barely use them and wrote this based on this wiki page about tables, so I apologize if something I said was wrong. I also typed all of this on mobile so I can’t even test my script.

0
use i=1 instead of i=0, as there is no 0th/0st item in a table 1xj7 1 — 6y
0
Couldn't you just do `tableToBeCleand = {}` thus removing everything in it? theCJarmy7 1293 — 6y
0
Sorry, I said I don’t know lot about tables right now and I thought I had to use table.remove for that. Didn’t know you can just simply do that. User#20279 0 — 6y
Ad

Answer this question