Filter Javascript
-
What is
Filter()?filter()is a method of theArrayobject.- It creates a new array with all elements that pass a test implemented by the provided function.
- An element makes it to the new array if the function returns true for that element.
const nums = [1, 2, 3, 4];
const moreThanTwo = nums.filter((current, index, originalArray) => {
return current > 2;
});
console.log(moreThanTwo) // [3, 4]