The array filter method takes a function as an argument.  Like other array helper methods, the function takes one argument that will be used as a reference to each array element.  The function must return true if the element should be included in the resulting array.

In the example below, each number gets assigned to the number variable and the function will return true if the number is greater than 50.

var numbers = [15, 25, 35, 45, 55, 65, 75, 85, 95];

var filteredNumbers = numbers.filter(function(number){
    return number > 50;            
});

console.log(filteredNumbers);

Here’s the same example using the arrow notation:

var numbers = [15, 25, 35, 45, 55, 65, 75, 85, 95];

var filteredNumbers = numbers.filter((number)=>{return number > 50});

console.log(filteredNumbers);

Here’s another example of filter using a function to generate an array of rejected items:

function reject(array, iteratorFunction) {
  var filteredItems = array.filter(iteratorFunction);
  return array.filter(function(item){
      return !filteredItems.includes(item);
  });
}

var numbers = [10, 20, 30];
var lessThanFifteen = reject(numbers, function(number){
  return number > 15;
}); 

console.log(lessThanFifteen);