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.
- PHP | Filter and Filter Constant
- AngularJS | filter Filter
- How to iterate over filtered (ng-repeat filter) collection of objects in AngularJS ?
- Extract unique objects by attribute from array of objects.
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.