Easy javascript

Filter even numbers

Problem

From [1,2,3,4,5,6] print only even numbers.

Hints
  • Use filter with n % 2 === 0

Your practice code

Ready — edit the code above and click Run.

Solution

const arr = [1, 2, 3, 4, 5, 6];
console.log(arr.filter(n => n % 2 === 0));

Try solving on your own first, then reveal the official answer.

Explanation

filter returns a new array—immutable pattern preferred in React state updates.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details