Creates a new array with all elements that pass the test function.
Syntax
arr.filter(callbackFn)Example
Enter values below to update the example in real time.
const→numbers→evens→filter→console→const numbers = [1, 2, 3, 4, 5, 6];
const evens = numbers.filter((n) => n % 2 === 0);
console.log(evens); // [2, 4, 6]