types.Array.contains
Method on every
arrayReports whether any element 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
true if some element equals value, false otherwise.
Notes
Equality is the same raw comparison == uses: a number compares by value against another number, and anything else compares by identity, so two distinct tables or arrays with the same contents are never equal here. No _cmp or _eq metamethod is consulted.
hasvalue is this same function registered under a second name.
Example
let a = [1, 2, 3];
println("a.contains(2) =", a.contains(2));
println("a.contains(9) =", a.contains(9));
// equality is by reference for tables/instances, not by contents
let t = {x = 1};
println("[t].contains(t) =", [t].contains(t)); // same table
println("[{x = 1}].contains(t) =", [{x = 1}].contains(t)); // an equal-looking but different tableOutput:
a.contains(2) = true
a.contains(9) = false
[t].contains(t) = true
[{x = 1}].contains(t) = falseSee also
hasvalue | Reports whether any element equals value. |
indexof | Finds the index of the first element that equals value. |
| array | class index |