Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
find and findIndex Helpers
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
You can’t perform that action at this time.