为javascript的Array添加个has(value),remove(value),removeAt(index)方法
function array_has(val)
{
var i;
for(i = 0; i < this.length; i++)
{
if(this[i] == val)
{
return true;
}
}
return false;
}
Array.prototype.has = array_has;
function array_remove(val)
{
var i;
var j;
for(i = 0; i < this.length; i++)
{
if(this[i] == val)
{
for(j = i; j < this.length - 1; j++)
{
this[j] = this[j + 1];
}
this.length = this.length - 1;
}
}
}
Array.prototype.remove = array_remove;
function array_removeAt(index)
{
var i;
if(index < this.length)
{
for(i = index; i < this.length - 1; i++)
{
this[i] = this[i + 1];
}
this.length = this.length - 1;
}
}
Array.prototype.removeAt = array_removeAt;
{
var i;
for(i = 0; i < this.length; i++)
{
if(this[i] == val)
{
return true;
}
}
return false;
}
Array.prototype.has = array_has;
function array_remove(val)
{
var i;
var j;
for(i = 0; i < this.length; i++)
{
if(this[i] == val)
{
for(j = i; j < this.length - 1; j++)
{
this[j] = this[j + 1];
}
this.length = this.length - 1;
}
}
}
Array.prototype.remove = array_remove;
function array_removeAt(index)
{
var i;
if(index < this.length)
{
for(i = index; i < this.length - 1; i++)
{
this[i] = this[i + 1];
}
this.length = this.length - 1;
}
}
Array.prototype.removeAt = array_removeAt;
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: 关于fseek不能定位大于2G文件的问题
- 下一篇: 指针偏移问题