The Array filter() is an inbuilt method, this method creates a new array with elements that follow or pass the given criteria and condition.
Few Examples have been implemented below for a better understanding of the concept
var newArray = arr.filter(callback(element[, index[, array]]) [, thisArg])
Parameter: This method accepts 2 parameters which was mentioned above and described below:
- Callback: The function is a predicate, to test each element of the array. Return true to keep the element, false otherwise. It accepts three arguments:
- element: The current element being processed in the array.
- index(Optional): The index of the current element being processed in the array.
- array(Optional): The array filter was called upon.
- thisArg(Optional): Value to use as this when executing the callback.
Example 1: The filter function filters all the numeric values in the array greater than 5
[ 6, 7, 8, 9, 10 ]
Example 2: The filter function filters all the words in the array which have length greater than 5
Example 3: The filter function filters all invalid id of users from the array.
- AngularJS | filter Filter
- PHP | Filter and Filter Constant
- PHP | Ds\Set filter() Function
- CSS | filter Property
- PHP | Ds\Map filter() Function
- p5.js | filter() Function
- Underscore.js | _.filter() with Examples
- AngularJS | currency Filter
- PHP | Ds\Sequence filter() Function
- PHP | Ds\Vector filter() Function
- How to use filter within controllers in AngularJS ?
- CSS | backdrop-filter Property
- AngularJS | orderBy Filter
- AngularJS | json Filter
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.