Skip to content

Instantly share code, notes, and snippets.

@ristaa
Created September 12, 2018 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ristaa/02425c4dbdeac6eba1c34485d73f3948 to your computer and use it in GitHub Desktop.
Save ristaa/02425c4dbdeac6eba1c34485d73f3948 to your computer and use it in GitHub Desktop.
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