Last active
February 29, 2016 16:59
-
-
Save edysegura/d5a6fd5dac426f8ac897 to your computer and use it in GitHub Desktop.
[JS] Check if has values with some
This file contains hidden or 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
var fruits = [ | |
{name:'apple', color:'red'}, | |
{name:'orange', color:'orange'}, | |
{name:'grape', color:'purple'} | |
]; | |
var hasFruit = function(fruitToCheck) { | |
return fruits.some(function(fruit) { | |
return fruit.name === fruitToCheck; | |
}); | |
}; | |
hasFruit('orange'); //true | |
hasFruit('pineapple'); //false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment