Answers for "lua remove duplicates from table"

0

lua remove duplicates from table

local test = {1,2,4,2,3,4,2,3,4,"A", "B", "A"}
local hash = {}
local res = {}

for _,v in ipairs(test) do
   if (not hash[v]) then
       res[#res+1] = v -- you could print here instead of saving to result table if you wanted
       hash[v] = true
   end

end
Posted by: Guest on May-04-2022

Code answers related to "lua remove duplicates from table"

Browse Popular Code Answers by Language