Sorry, I disagree. "Table" contains a value is slightly different than "array". Because for this question I can give two advises, none of which is acceptable for tables. 1. If it is a hardcoded array, like config, you can do this: ({apple = 1, banana = 1})[value]. 2. If it is an array, there is quite beautiful but ineffecient method: utils.swapKV(array)[value]
local found = false
for _, v in ipairs(fruits) do
if v == value then
found = true
break
end
end
if not found then
print ( value .. " is not a fruit" )
end
({apple = 1, banana = 1})[value]. 2. If it is an array, there is quite beautiful but ineffecient method:utils.swapKV(array)[value]