Garry's Mod Wiki

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

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...