How to make sure every single index of one table matches another table?

Im needing to check if an index matches every single other index in a table, but once the first one index matches it works; which I dont want

1 Like

You can just loop through the tables and check. You’d have to go through both and check if that index in the other table gives the same value. (Make sure to do both, since the 2nd might just be an extended version of 1st table, e.g {1}, {1,2}.)

local function whatever(firstTable, secondTable) -- get the two tables
	for i, v in pairs(firstTable) do -- go thru the first one
		if v ~= secondTable[i] then -- make sure any entry is the same as in the other table, otherwise return false
			return false
		end
	end

	for i, v in pairs(secondTable) do -- loop through the second table
		if v ~= firstTable[i] then -- same thing as for other loop
			return false
		end
	end

	return true
end
3 Likes

Just for color (@posatta’s answer is a fine way):

Why are you trying to do this? There might be a better way.

2 Likes