Filtering Arrays with Array.filter() in Javascript


Create a new array with all elements that pass the test implemented by the provided function.

Source Code

let numbers = [1, 2, 3, 4, 5];
let evenNumbers = numbers.filter(number => number % 2 === 0);
console.log(evenNumbers); // [2, 4]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments