⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 13.2.2 prototype属性.html

📁 javascript即用即差核心对象手册
💻 HTML
字号:
<script>
  //添加一个属性,用于统计删除掉元素地个数
  Array.prototype.removed=0;
  //添加一个方法,用于删除指定索引的元素
  Array.prototype.removeAt=function(index)
  {
    if(isNaN(index)||index<0)
	    {return false;}
	if(index>=this.length)
	    {index=this.length-1}
    for(var i=index;i<this.length;i++)
    {
       this[i]=this[i+1];
    }
    this.length-=1
	this.removed++;
  }
  //添加一个方法,输出数组中的全部数据
  Array.prototype.outPut=function(sp)
  {
      for(var i=0;i<this.length;i++)
	  {
	     document.write(this[i]);
		 document.write(sp);
	  }
	  document.write("<br>");
  }
  //定义数组
   var arr=new Array(1,2,3,4,5,6,7,8,9);
   //测试添加的方法和属性
   arr.outPut(" ");
   document.write("删除一个数据<br>");
   arr.removeAt(2);
   arr.outPut(" ");
   arr.removeAt(4);
   document.write("删除一个数据<br>");
   arr.outPut(" ")
   document.write("一共删除了"+arr.removed+"个数据");
</script>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -