Skip to content

IndexOf

Dennis Corvers edited this page Oct 23, 2026 · 1 revision

Enumerable:indexOf

Returns the 1-based position of the first value equal to a requested item.

Syntax

position = values:indexOf(item, comparer)

Parameters

Parameter Type Description
item any Value to locate.
comparer function(value, item) (optional) Returns true when the values are considered equal.

Returns

The 1-based position of the first match, or -1 if no match is found.

Remarks

The returned position counts elements in iteration order; it is not necessarily the key used by the source iterator.

Example

local position = LuaQ.from({
    { item = "rune scimitar" },
    { item = "abyssal whip" },
})
    :indexOf({ item = "abyssal whip" },
        function(entry, wanted) return entry.item == wanted.item end)
-- 2

See also

Contains · ElementAt · Functions

Clone this wiki locally