Skip to content

Instantly share code, notes, and snippets.

@edysegura
Last active February 29, 2016 16:59
Show Gist options
  • Save edysegura/d5a6fd5dac426f8ac897 to your computer and use it in GitHub Desktop.
Save edysegura/d5a6fd5dac426f8ac897 to your computer and use it in GitHub Desktop.
[JS] Check if has values with some
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