โ Back to Loops
Question 33
filter: Keep Even Numbers
filter: Keep Even Numbers
Use filter to keep only the even numbers from the array, then print them as comma-separated values.
Array:
[1, 2, 3, 4, 5, 6]
Expected output:
2,4,6
Steps:
1. Use filter on the numbers array
2. Keep numbers where number % 2 === 0
3. Print the filtered array with join(',')Expected Output:
2,4,6
Topics:
LoopsArraysfilter
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (clog, fn, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.