Created
August 7, 2014 14:46
-
-
Save ozee31/6ec680f4c67a1b451f1c to your computer and use it in GitHub Desktop.
Indique si une valeur appartient à un tableau
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
/** | |
* Checks if a value exists in an array | |
* @param {mixed} needle : The searched value | |
* @param {array} haystack : The array | |
* @return {bool} | |
*/ | |
var in_array = (function (needle, haystack) { | |
return ( haystack.indexOf(needle) !== -1 ); | |
}); | |
/** EXEMPLES */ | |
test = ['foo', 'bar']; | |
in_array('foo', test); // true | |
in_array('ozee31', test); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment