Is there any way or method to remove all duplicate numbers or strings from a table? My script inserts textbuttons with numbers pulled from a table into a gui, but due the duplicates some of the buttons have the same text.
Hi Kip,
local tab_with_values = {1, 3, 4, "Whatever", "AnyValue", "Any Value", 3}; local new_tab = {}; for _, value in next, tab_with_values do if not new_tab[value] then new_tab[value] = true; end end
-- When you know the value you're looking for local val_i_want = "AnyValue"; local val_u_want = new_tab[val_i_want]; -- This will index the value and return the exact value for you. -- When you need to loop through the table and maybe don't know the value or want to just change all values inside of the table. for value, _ in next, new_tab do print(value) -- This is the value, since the value has exchanged places with the index, like I discussed before. end
Thanks,
Best regards,
~~ KingLoneCat