Select with filter()
.filter() returns a new array containing only the items for which your
function returns true.
[1, 2, 3, 4].filter((n) => n > 2); // [3, 4]
Your task
Write onlyEvens that returns a new array containing only the even numbers, in
their original order.
β‘ 30 XP
π§± Code blocks
Drag a block into the editor, or tap it to drop it in where your cursor is. Add them in order to build your answer.
solution.jsRuns in your browser
Loading editorβ¦
Tests3 to pass
[1,2,3,4] β [2,4]
no evens β []
[] β []
Run your code to check these.