Skip to content

Instantly share code, notes, and snippets.

@ozee31
Created August 7, 2014 14:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozee31/6ec680f4c67a1b451f1c to your computer and use it in GitHub Desktop.
Save ozee31/6ec680f4c67a1b451f1c to your computer and use it in GitHub Desktop.
Indique si une valeur appartient à un tableau
/**
* 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