any :: Enumerable

any([iterator = Prototype.K]) -> Boolean Determines whether at least one element is boolean-equivalent to true, either directly or through computation by the provided iterator.

The code obviously short-circuits as soon as it finds an element that “passes” (that is boolean-equivalent to true). If no iterator is provided, the elements are used directly. Otherwise, each element is passed to the iterator, and the result value is used for boolean equivalence.

Examples

[].any()

// -> false (empty arrays have no elements that could be true-equivalent)

$R(0, 2).any()

// -> true (on the second loop cycle, 1 is true-equivalent)

[2, 4, 6, 8, 10].any(function(n) { return 0 == n % 3; })

// -> true (the iterator will return true on 6: the array does have 1+ multiple of 3)

$H({ opt1: null, opt2: false, opt3: '', opt4: 'pfew!' }).any(function(pair) { return pair.value; })

// -> true (thanks to the opt4/'pfew!' pair, whose value is true-equivalent)

See also

If you need to determine whether all elements match a criterion, you would be better off using all.

Enumerable: all

Prototype API 1.5.0 - prototypejs.org