You want to be able to filter arrays based on a boolean condition.
Use Array.filter (ECMAScript 5):
In pre-EC5 implementations, extend the Array prototype to add a filter function which will take a callback and perform a comprehension over itself, collecting all elements for which the callback is true. Be sure to check if the function is already implemented before overwriting it:
This is similar to using ruby’s Array#select method.