table.HasValue issue

How would I go about using a table in the second part of table.HasValue instead of having to repeat it in if statements?
Example:
How would I get something like this:



local extensions1 = { "jpg", "jpeg", "png", "gif"}
elseif table.HasValue( linkpart1, extensions1 ) then 


instead of



elseif table.HasValue( linkpart1, "jpg" ) or table.HasValue( linkpart1, "jpeg" ) or table.HasValue( linkpart1, "gif" ) or table.HasValue( linkpart1, "png" )  then


Thanks for any help in advance :slight_smile:

if( table.HasValue( extensions1, linkpart1 ) )? will be if the table extensions1 has the value linkpart1 which sound like it should be jpg, png?
or:



local _table = {};
_table[ "jpg" ] = true;
_table[ "png" ] = true;

if( _table[ "jpg" ] ) then
// extension is in table
end


If you need to individually check each string then recursion would be the neatest way.

[lua]
local extensions1 = { “jpg”, “jpeg”, “png”, “gif” }

for _, extension in pairs( extensions1 ) do
if table.hasValue( linkpart1, extension ) then
– Code here
break
end
end
[/lua]

This.
I really don’t see why people use table.HasValue for these things. Very few people consider associative array structure, and that grinds my gears.



local extensions1 = {jpg = true, jpeg = true, png = true, gif = true}
if extensions1[linkpart1] then
     -- code
end


e: ninja’d, but most of the time there’s absolutely no reason to use table.HasValue because Lua gives you hashtables for free – it just shows you don’t know the language’s biggest selling points