Skip to content

Instantly share code, notes, and snippets.

@joelpalmer
Created July 6, 2015 16:11
Show Gist options
  • Save joelpalmer/77c09d3e9a1e89a6e274 to your computer and use it in GitHub Desktop.
Save joelpalmer/77c09d3e9a1e89a6e274 to your computer and use it in GitHub Desktop.
Array.prototype.find() examples
/**
* Created by Joel Palmer on 7/6/2015.
*
* ES6 - FF only as of now
*
* Polyfill: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find
*/
function isEven(el, idx, array){
return el % 2 == 0;
}
var test = 3;
var test2 = 2;
console.log(isEven(test));
console.log(isEven(test2));
var nums = [3, 9, 11, 14];
console.log(nums.find(isEven));
console.log(nums.find(function (el, idx, array){
return el % 2 == 0;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment