Last active
November 14, 2019 13:43
-
-
Save iandesj/1ef0eeaf044b63b74c461154e249d609 to your computer and use it in GitHub Desktop.
Examples of find() vs for loop
This file contains hidden or 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 aFruit = fruits.find((element) => { | |
return element.includes('apple'); | |
}); | |
let aFruit; | |
for (let i = 0; i < fruits.length; i++) { | |
if (fruits[i].includes('apple')) { | |
aFruit = fruits[i]; | |
break; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment