Call as
Functions.collections.index(array, value)
Record it as a dependency named Functions.collections.index (accepting the completion does this), then call it by that name.
What it does
Return the first key whose value equals the supplied value during pairs traversal. Nil or false input tables and absent values return nil. Multiple matching keys have no guaranteed selection order.
Arguments
| Name | Type | What it does |
|---|---|---|
array | table | nil | false | Table to search; nil or false returns nil. |
value | any | Value compared with each table value using Lua equality. |
Returns
| 1 | any | Matching key, including a false key, or nil when no match exists. |
|---|
Editions
Built In helpers are registered on every edition. What differs is the game API they read; where one is missing the helper falls back or returns nil with a reason.
It reads no game API directly.
Example
local priority = { "Fire", "Frost", "Arcane" }
local slot = Functions.collections.index(priority, "Frost")
return slot ~= nil and slot <= 2Source
Functions/collections.lua, line 76. Read only in game; Duplicate makes an editable copy.
Functions.collections.index(array, value)
if not array then return nil end
for idx,v in pairs(array) do
if (v == value) then
return idx
end
end