The filter() method basically outputs all the element object that pass a specific test or satisfies a specific function. The return type of the filter() method is an array that consists of all the element(s)/object(s) satisfying the specified function.
var newArray = arr.filter(callback(object[, ind[, array]])[, Arg])
- Callback is a predicate, to test each object of the array. Returns True to keep the object, False otherwise. It takes in three arguments:
- Object: The current object being processed in the array.
- ind (Optional): Index of the current object being processed in the array.
- array (Optional): Array on which filter was called upon.
- Arg (Optional): Value to use(.this) when executing callback.
The above example returns all the positive elements in a given array.
- How to iterate over filtered (ng-repeat filter) collection of objects in AngularJS ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.