Created
September 12, 2018 11:49
-
-
Save ristaa/02425c4dbdeac6eba1c34485d73f3948 to your computer and use it in GitHub Desktop.
find and findIndex Helpers
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 fruit = ['banana','pear','ananas', 'apple', 'peach']; | |
let stuffs = ['desk', 'pen', 'wardrobe']; | |
function findApple(newFruit){ | |
return newFruit==='apple'; | |
} | |
console.log(fruit.find(findApple)); // "apple" | |
console.log(stuffs.find(findApple)); // undefined | |
console.log(fruit.findIndex(findApple)); // 3 | |
console.log(stuffs.findIndex(findApple)); // -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment