一、var ArrayX = [0];
//判斷元素是否在數組裏
Array.prototype.inArray = function(e)
{
for(i=0;i<this.length && this[i]!=e;i++);
return !(i==this.length);
}數組
使用方法:ArrayName.inArray(val)
二、//刪除數據元素
Array.prototype.remove=function(dx)
{
if(isNaN(dx)||dx>this.length){return false;}
for(var i=0,n=0;i<this.length;i++)
{
if(this[i]!=this[dx])
{
this[n++]=this[i]
}
}
this.length-=1
}this
使用方法:ArrayName.remove(xiabiao);
三、//獲取元素在數組中的位置
function searchKeys(needle, haystack){
var result = [];
for (i in haystack)
{
if (haystack[i] == needle)
{
result.push(i);
}
}
return result;
}prototype
使用方法:searchKeys(val,ArrayName);rem