types.Array.indexof
Method on every
arrayFinds the index of the first element that equals value.
The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing
... from the prose below, not from the signature.Parameters
value | any | the value to look for |
Return value
The index of the first match, or null if none matched.
Notes
Equality is the same raw comparison contains uses: identity for tables, arrays, classes and instances, value for numbers and strings, and no _cmp or _eq metamethod. Use findindex when the match is a condition rather than a fixed value.
Example
let a = ["a", "b", "c"];
println("a.indexof(\"b\") =", a.indexof("b"));
println("a.indexof(\"z\") =", a.indexof("z"));
let t = {};
println("[t, {}].indexof(t) =", [t, {}].indexof(t)); // reference identity, not structural equalityOutput:
a.indexof("b") = 1
a.indexof("z") = null
[t, {}].indexof(t) = 0See also
contains | Reports whether any element equals value. |
findindex | Finds the index of the first element for which callback returns a true value. |
| array | class index |