[javascript] 数组扩展操作
/**
*
* 用来判断数组是否包含某个元素
* @author niaoren 2011-12-27
*/
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));
}
/**
* 删除指定下标的元素
*
* @author niaoren 2012-02-28
*/
Array.prototype.remove = function(index)
{
if (isNaN(index) || index > this.length)
{
return false;
}
this.splice(index, 1);
}
/**
* 数组克隆
*
* @author niaoren 2012-02-28
*/
Array.prototype.clone = function()
{
return this.slice(0);
}
*
* 用来判断数组是否包含某个元素
* @author niaoren 2011-12-27
*/
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));
}
/**
* 删除指定下标的元素
*
* @author niaoren 2012-02-28
*/
Array.prototype.remove = function(index)
{
if (isNaN(index) || index > this.length)
{
return false;
}
this.splice(index, 1);
}
/**
* 数组克隆
*
* @author niaoren 2012-02-28
*/
Array.prototype.clone = function()
{
return this.slice(0);
}