For the Prototype fans:
Array.prototype.indexOf = function(o)
{
for (var i = 0; i < this.length; i++)
{
if ( typeof o == 'function' )
{
if ( o(this[i],i) )
{
return i;
}
} else if ( typeof o == 'object' && typeof
this[i]
== 'object' ) {
var k = $A($H(o).keys());
var total = k.inject(0,function(sum,p)
{
if ( this[p] == o[p] )
{
return sum + 1;
} else {
return sum;
}
}.bind(this[i]));
if (total == k.length)
{
return i;
}
} else {
if (this[i] == o)
{
return i;
}
}
}
return -1;
};
var aList = $A(
[
1,
'a',
{
'year':2006,
'make':'Porsche',
'model':'Cayman S'
}
]);
alert(aList.indexOf(1));
alert(aList.indexOf({'year':2006}));
alert(aList.indexOf(function(o,i) { return ( o == 'a' ); }));
Alert(ed) results: 0,2,1
You get the idea
