Created
August 31, 2015 03:41
-
-
Save dented/b9a299308d8fa49f52e1 to your computer and use it in GitHub Desktop.
Find Value in Array
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 indexOf = function(needle) { | |
if(typeof Array.prototype.indexOf === 'function') { | |
indexOf = Array.prototype.indexOf; | |
} else { | |
indexOf = function(needle) { | |
var i = -1, | |
index = -1; | |
for(i = 0; i < this.length; i++) { | |
if(this[i] === needle) { | |
index = i; | |
break; | |
} | |
} | |
return index; | |
}; | |
} | |
return indexOf.call(this, needle); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment