Created
July 6, 2015 16:11
-
-
Save joelpalmer/77c09d3e9a1e89a6e274 to your computer and use it in GitHub Desktop.
Array.prototype.find() examples
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
/** | |
* 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