PHP的數(shù)組函數(shù)in_array()非常方便,可JS就不是了。其實(shí)我很不喜歡JS的數(shù)組~
別說了,直接上方法
復(fù)制代碼 代碼如下:
Array.prototype.in_array = function(e)
{
for(i=0;i<this.length;i++)
{
if(this[i] == e)
return true;
}
return false;
}
復(fù)制代碼 代碼如下:
Array.prototype.in_array = function(e)
{
for(i=0;i<this.length && this[i]!=e;i++);
return !(i==this.length);
}
復(fù)制代碼 代碼如下:
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));
}
復(fù)制代碼 代碼如下:
var aa = new Array(1,2,'aa','bbb',4,5);
alert(aa.in_array(3));
alert(aa.in_array('aa'));
新聞熱點(diǎn)
疑難解答
圖片精選