Skip to content

Instantly share code, notes, and snippets.

@iandesj
Last active November 14, 2019 13:43
Show Gist options
  • Save iandesj/1ef0eeaf044b63b74c461154e249d609 to your computer and use it in GitHub Desktop.
Save iandesj/1ef0eeaf044b63b74c461154e249d609 to your computer and use it in GitHub Desktop.
Examples of find() vs for loop
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