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.
- PHP | Filter and Filter Constant
- AngularJS | filter Filter
- ES6 | Array forEach() Method
- Array Helper Methods in ES6
- How to clone array in ES6 ?
- ES6 | Array
- ES6 | RegEx
- ES6 | Promises
- Difference between node.js require and ES6 import and export
- Introduction to ES6
- Motivation to bring symbols in ES6
- ES6 | Math
- ES6 | Number
- ES6 | Dialog Boxes
- ES6 | Page Printing
- ES6 | Page Redirect
- ES6 | Boolean
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.