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, 6];
let evenNumbers = numbers.filter(function(num) {
  return num % 2 === 0;
});
console.log(evenNumbers); // [2, 4, 6]
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments