Filter Arrow Function (ES6)

share link

by vsasikalabe dot icon Updated: Mar 17, 2023

technology logo
technology logo

Guide Kit Guide Kit  

We can use arrow functions with JavaScript Array methods like map, reduce, filter, etc. With these methods, you can make complete array transformations in one line by using arrow functions. filter() method will create a new array with all elements that filtered the element with some specific conditions. 

The Array filter() is an inbuilt method, and this function creates a new array with elements that follow the given criteria and conditions.  


var newArray = arr.filter(callback(element[, index[, array]]) 

[, thisArg]) 

Parameter: This method accepts two parameters: 

Callback: This function is used to test each element of the array. It returns true to keep the element.  

Element: The current element being executed in the array. Otherwise, it is false. It accepts three arguments: 

  • index(Optional): The current element's index is executed in the array. 
  • array(Optional): The array filter was called. 
  • thisArg(Optional): Value to use (when executing the callback function). 

Here is an example of how to ES6 Filter Arrow functions: