Finders Keepers; what if I want to find more all the nums =%2 ===0?

Finders Keepers; what if I want to find more all the nums =%2 ===0?
0

#1

Tell us what’s happening:
Hello Campers!

I know I succeded this challenge( returns the first element in the array that passes a truth test) but
I wondering what should I do to find all the numbers which remainders are zero? Should I use a map() and push() methods?

Your code so far



function findElement( arr , func ) {
     return arr.filter(func)[0];
}


findElement([1, 2, 3, 4], num => num % 2 === 0);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/finders-keepers


#2

This:

arr.filter(func)

is returning an array of all the elements that match the test. This:

[0]

is telling it that you only want the first element of that array or matches.

If you remove that last part, your function will return an array of all matches.