table/FindPrev

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Also menu state)
 
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=FindPrev
 
|Parent=table
 
 
|Description={{Deprecated|Instead, iterate your table with ipairs, storing the previous value and checking for the target. Non-numerically indexed tables are not ordered.}}
 
|Description={{Deprecated|Instead, iterate your table with ipairs, storing the previous value and checking for the target. Non-numerically indexed tables are not ordered.}}
 
Returns the value positioned before the supplied value in a table. If it isn't found then the last element in the table is returned
 
Returns the value positioned before the supplied value in a table. If it isn't found then the last element in the table is returned
Line 22: Line 20:
 
|type=any
 
|type=any
 
|desc=Found element
 
|desc=Found element
 +
}}
 +
{{Example
 +
|Description=Print the previous item the value "b" of the table
 +
|Code=local tbl = {"a", "b", "c"}
 +
 +
print(table.FindPrev(tbl, "b"))
 +
|Output=a in console
 
}}
 
}}

Latest revision as of 20:18, 14 May 2018

 table.FindPrev( )

Contents

Description

This feature is deprecated.
You should avoid using it as it may be removed in a future version.

Instead, iterate your table with ipairs, storing the previous value and checking for the target. Non-numerically indexed tables are not ordered.

Returns the value positioned before the supplied value in a table. If it isn't found then the last element in the table is returned

Arguments

table tbl

Table to search

Arguments

any value

Value to return element before

Returns

any

Found element

Examples

Example

Print the previous item the value "b" of the table

local tbl = {"a", "b", "c"}

print(table.FindPrev(tbl, "b"))

Output:

a in console
Personal tools
Navigation