Skip to content

Mangler.filter()

Robert Biro edited this page Oct 12, 2016 · 2 revisions

Removes all array items or object properties that do not pass the test.

Mangler.filter(object, test)
Parameter Type Default Description
object Array
Object
Mangler
The object to remove items from.
test Test {} The test expression to check against.

Returns

Returns the processed object.


Removes all items from the object that do not pass the test. For more information on test expressions, see Mangler.test().

This function changes the original object by removing its items or properties. To avoid it, you can either call Mangler.clone() to clone the object first, or use Mangler.find() which returns matching items in a new array.

Example

a = [1, 2, 3, 4];

Mangler.filter(a, { $gt: 2 });    // a = [3, 4]