Last active
June 21, 2018 05:09
-
-
Save mirajehossain/2c9ee55d90036ed087acc7fe84aefbcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers = [1,2,3,4,5,6,7,8,9,10]; | |
// using for loop | |
let evenNumbers = []; | |
for(let i=0; i<numbers.length; i++){ | |
if(numbers[i] % 2 === 0) evenNumbers.push(numbers[i]); | |
} | |
console.log(evenNumbers); | |
// using filter | |
let evenNumbers = numbers.filter(item=> item % 2 === 0); | |
console.log(evenNumbers); | |
// OUTPUT: [2, 4, 6, 8, 10] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment