Last active
November 14, 2019 13:46
-
-
Save iandesj/9437862dbc7124342a514fd6b7cb0ca7 to your computer and use it in GitHub Desktop.
Examples of filter() vs for loop
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
const fruits = [ 'pineapple', 'apple', 'banana', 'pear' ]; | |
const matchedFruits = fruits.filter((element) => { | |
return element.includes('apple'); | |
}); | |
let matchedFruitsAgain = []; | |
for (let i = 0; i < fruits.length; i++) { | |
if (fruits[i].includes('apple')) { | |
matchedFruitsAgain.push(fruits[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment