Created
June 22, 2013 19:44
-
-
Save edubskiy/5842333 to your computer and use it in GitHub Desktop.
Check if elem contains within array
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
/** | |
* Check if elem contains within array | |
* | |
* @param array | |
* @param elem checking value | |
* @returns {int} | |
*/ | |
inArray: function(array, elem) { | |
var indexOf = [].indexOf; | |
if (indexOf) { | |
return indexOf.call(array, elem); | |
} | |
for ( var i = 0, length = array.length; i < length; i++ ) { | |
if ( elem === array[ i ] ) { | |
return i; | |
} | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment