Quirrel4.41.0

types.Array.hasvalue

Method on every array
pure array.hasvalue(value): any

Reports 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

valueanythe value to look for

Return value

true if some element equals value, false otherwise.

Notes

This is contains registered under a second name; the two are the same function and behave identically, including the raw, identity-based equality described there.

Example

examples/types/array/hasvalue.nut
let a = [1, 2, 3];
println("a.hasvalue(2) =", a.hasvalue(2), "a.hasvalue(9) =", a.hasvalue(9));
println("a.hasvalue(2) == a.contains(2):", a.hasvalue(2) == a.contains(2));   // hasvalue and contains share one implementation
Output:
a.hasvalue(2) = true a.hasvalue(9) = false
a.hasvalue(2) == a.contains(2): true

See also

containsReports whether any element equals value.
indexofFinds the index of the first element that equals value.
arrayclass index