梅开二度 激情超越

~~常用激扬的句子去激励自己的学生,为什么自己却莫名的沉沦了!~~

为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;

posted on 2006-12-19 09:27 梅开二度 激情超越 阅读(1553) 评论(0)  编辑 收藏 引用 网摘 所属分类: Javascript


只有注册用户登录后才能发表评论。

My Links

Blog Stats

留言簿(3)

随笔分类(22)

随笔档案(21)

文章分类(48)

文章档案(44)

相册

收藏夹(40)

Favorite site

My Friends

搜索

最新评论