findAll

findAll(iterator[, context]) -> Array

Returns all the elements for which the iterator returned true. Aliased as select.

This is a sort of all-purpose version of grep (which is specific to String representations of the values). findAll lets you define your predicate for the elements, providing maximum flexibility.

The optional context parameter is what the iterator function will be bound to. If used, the this keyword inside the iterator will point to the object given by the argument.

Examples


$R(1, 10).findAll(function(n) { return 0 == n % 2; })
// -> [2, 4, 6, 8, 10]

[ 'hello', 'world', 'this', 'is', 'nice'].findAll(function(s) {
  return s.length >= 5;
})
// -> ['hello', 'world']

See also

The reject method is the opposite of this one. If you need to split elements in two groups based upon a predicate, look at partition.