PHP's Array function In_array () is very convenient, but JS is not. In fact, I do not like the JS array ~
Stop it, go directly to the method
Copy Code code as follows:
Array.prototype.in_array = function (e)
{
for (i=0;i<this.length;i++)
{
if (this[i] = = e)
return true;
}
return false;
}
Or
Copy Code code as follows:
Array.prototype.in_array = function (e)
{
For (i=0;i<this.length && this[i]!=e;i++);
Return! (I==this.length);
}
Both of these are possible. is actually a form, the writing is not the same.
Of course, there is another way I recommend it,
Copy Code code as follows:
Array.prototype.s=string.fromcharcode (2);
Array.prototype.in_array=function (e)
{
var r=new RegExp (this. S+e+this. S);
Return (R.test) (this. S+this.join (this. S) +this. S));
}
I personally like this, do not understand what is the relationship, you just use my code to write good, quack.
Analog data detection is good
Copy Code code as follows:
var aa = new Array (1,2, ' AA ', ' BBB ', 4,5);
Alert (Aa.in_array (3));
Alert (Aa.in_array (' AA '));