JavaScript filter() method

This method returns a new array containing the elements that pass a certain test performed on an original array.

 Syntax:

let newArray = oldArray.filter((currentValue, index, array) {
// Returns element to new Array
});

Parameters:

  • currentValue: The current element’s value.
  • index: The current element’s array index.
  • array: The array object to which the current element belongs.

Return Value:

A new array object containing the filtered elements that satisfied the condition of the function

How to use map and filter simultaneously on an array using JavaScript ?

In this article, we are given an array and the task is to use the filter and map function simultaneously to the given array.

Similar Reads

JavaScript filter() method

This method returns a new array containing the elements that pass a certain test performed on an original array....

JavaScript map() method

This method is used to apply a function on every element in an array and returns a new array of the same size as the input array....

Approach

Firstly, by using filter() function we will retrieve those elements from an array that satisfies the given condition. As the filter() method will return the array with the required elements. Now we will apply map() method to perform the specified operations on all elements of the array returned by filter() method....

Contact Us