types.Array.findindex
Finds the index of the first element for which callback returns a true 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
callback | function | callback(value, [index], [array]), tested against each element, in order |
Return value
The index of the first match, or null if none matched.
Errors
Whatever callback throws, on the first element where it throws.
Notes
callback gets exactly as many of the arguments listed above as it declares parameters for, and never more.
Use indexof instead when the target is a plain value to compare, rather than a condition to test.
Example
let a = [10, 20, 30];
println("a.findindex(v > 15) =", a.findindex(function(v) { return v > 15 }));
println("a.findindex(v > 999) =", a.findindex(function(v) { return v > 999 })); // not found -> nullOutput:
a.findindex(v > 15) = 1
a.findindex(v > 999) = nullSee also
findvalue | Finds the first element for which predicate returns a true value. |
indexof | Finds the index of the first element that equals value. |
| array | class index |