Garry's Mod Wiki



boolean table.HasValue( table tbl, any value )


Checks if a table has a value.

This function is very inefficient for large tables (O(n)) and should probably not be called in things that run each frame. Instead, consider a table structure such as example 2 below. Also see: Tables: Bad Habits
For optimization, functions that look for a value by sorting the table should never be needed if you work on a table that you built yourself.


1 table tbl
Table to check
2 any value
Value to search for


1 boolean
Returns true if the table has that value, false otherwise


Creates a table with values "123" and "test" and checks to see it the table holds value "apple"

local mytable = {"123", "test"} print(table.HasValue(mytable, "apple"), table.HasValue(mytable, "test"))
Output: false true


Example usage of O(1) associative array structure

local mytable = { ["123"] = true, test = true } print(mytable["apple"], mytable["test"])
Output: nil true

Special Pages



Render Time: 28ms

DB GetPage 4
Generate Html 4
SaveChanges (1) 12
Render Body 0
Render Sidebar 5