Remove "blacklisted" items in a table from a seperate table

Hello; I have two tables and they look similar to this.

local Locations = {"[AK-47] - 1000$", "[Food] - 5$", "[Test] - 10$")
local Remove = {"[Food]", "[AK-47]"}

I am trying to figure out an efficient way to remove all matches within a table.

The output I’m looking for is just “[Test] - 10$” with the “[]”. I have been trying to find an efficient way to remove all the matches within the Remove table without having to do them all individually.

I’ve tried multiple different ways and can’t seem to find a good solution that doesn’t just break and remove all the values in the table.

You could use string matching, but that isn’t going to be very efficient. I would instead recommend using a dictionary to map keys to values, where the key is your item name and the value is your item price. Then. When you want to remove an item, you can just remove it by the key name. That would be the most efficient solution as far as I can tell. Hope this helps!

local Locations = {"[AK-47] - 1000$", "[Food] - 5$", "[Test] - 10$"}
local Removes = {"[Food]", "[AK-47]"}

for i1, Remove in ipairs(Removes) do
	for i2, Location in ipairs(Locations) do
		if string.find(Location, Remove) then
			table.remove(Locations, i2)
		end
	end
end

for _, Location in ipairs(Locations) do
	print(Location)
end

Output:

image