DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Array.indexOf Fix //JavaScript Function
Just an idiot fix to increase the number of my posts =b
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com
[].indexOf || (Array.prototype.indexOf = function(v){
for(var i = this.length; i-- && this[i] !== v;);
return i;
});
example
var x = [0,1,2,3]; alert(x.indexOf(2)); alert(x.indexOf(4));





Comments
Snippets Manager replied on Sun, 2006/10/22 - 6:18pm
Snippets Manager replied on Mon, 2012/05/07 - 2:26pm
Cristian Carlesso replied on Fri, 2006/08/25 - 11:46am
Snippets Manager replied on Mon, 2006/08/28 - 5:26pm
[].indexOf || (Array.prototype.indexOf = function(v,n){ n = (n==null)?0:n; var m = this.length; for(var i = n; i < m; i++) if(this[i] == v) return i; return -1; });examplevar x = [0,1,2,3,1]; alert(x.indexOf(1)); alert(x.indexOf(1,2)); alert(x.indexOf(3)); alert(x.indexOf(4));