JavaScript’s .filter() function is a higher-order array function that accepts a callback function as an argument. It is non-destructive — it will create a new array, and then filter the contents of the original array, based on the callback’s parameters, into the new array.
Here’s an example of our filter function in action. Let’s say we have this array of numbers here:
let arr = [1,2,3,4,5,6,7,8]
And we want to filter out the even numbers into a new array. One way we can do this is to create a function that takes in an array of integers as an argument. We would create a new array within this function and then create a for-loop that would iterate over each index of the original array. In each iteration, there will be a check to see if the integer is divisible by 2. If the integer is divisible, then it is pushed into the new array. The new array is then returned after the for-loop.

#react #software-development #software-engineering #javascript #programming

Using The Filter Function in JavaScript and React!
1.35 GEEK