DEV Community

Discussion on: Filter Arrays with the Javascript Filter() Method

Collapse
 
budisalah profile image
Budi Salah 🐋 • Edited

Hello guys.
I need some help, please 😥

At the end of this post, @sarah_chima said

Remember the example mentioned at the beginning of this post? Can you try to use the filter method to achieve the same thing?

I tried to do it but I can't. I want the final output to be like this using filter method:

[4, 3, 36, 7]

Thanks, guys.

Collapse
 
vier31 profile image
Jan Schröder

You would need to put the if statement in the callback of the filter()

const oddSqrRoots = numbers.filter(num => num % 2 != 0)