How to remove values from a table using another table

is there a simple way to remove values from a table using another table?
besides looping through both tables to remove individual elements one at a time?

local mainTable = { "apple", "banana", "cherry", "orange", "blueberry" }
local removeTable = { "banana", "orange" }

then the result would be

newTable = { "apple", "cherry", "blueberry" }

i couldnt find anything but so far this

for i, v in pairs(removeTable) do
    for j, w in pairs(mainTable) do
        if w == v then
            table.remove(mainTable, j)
        end
    end
end

This code won’t work for the following input:

local removeTable = { "banana", "orange", "apple" }

If you want to use table.find you’d need to do something like this:

for i=#mainTable,1,-1 do
	if table.find(removeTable, mainTable[i]) then
		table.remove(mainTable, i)
	end
end
1 Like