Posted 27 January 2014 - 01:05 PM
I am looking at ways to remove am element from a table and found table.remove(). my question is there any other way to get the same result, and what is recommended?
tTable[5] = nil
Using table.remove requires more computing power and is thus slower, so it's better to not use it unless nessacary. Not that big of a deal though to be honest, but it's something to keep in mind.
local myTable = {"one","two","three","four"}
print("Initialize table and print ...")
for i = 1,#myTable do
print (myTable[i])
end
print()
print("Set table[2]=nil and reprint ...")
myTable[2]= nil
for i = 1,#myTable do
print (myTable[i])
end
print()
print("Re intialize table, use table.remove() and reprint ...")
myTable = {"one","two","three","four"}
table.remove(myTable,2)
for i = 1,#myTable do
print (myTable[i])
end
Initialize table and print…
one
two
three
four
Set table[2]=nil and reprint ...
one
Re intialize table, use table.remove() and reprint …
one
three
four