黑马程序员技术交流社区

标题: JavaScript中Array对象的一些方法问题 [打印本页]

作者: 黄树人    时间: 2012-9-7 19:36
标题: JavaScript中Array对象的一些方法问题
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <title>练习</title>
  6. </head>

  7. <body>
  8.         <script type="text/javascript">
  9.                 //Array对象
  10.                 var arr1=[23,42,12,29];
  11.                 var arr2=[21,53];
  12.                 var length=arr1.length;
  13.                 document.write("数组的长度是:"+length+"<br/>");
  14.                 document.write("concat后的数组为:"+arr1.concat(arr2)+"<br/>");
  15.                 document.write("join后的数组为:"+arr1.join("-")+"<br/>");
  16.                 document.write("pop数组:"+arr1.pop()+"<br/>");
  17.                 document.write("pop后的数组为:"+arr1+"<br/>");
  18.        
  19.         </script>
  20. </body>
  21. </html>
复制代码
在Array对象中定义了2个数组,调用concat方法把2个数组连起来
输出结果为23,42,12,29,21,53,但arr1数组还是没变,
可调用pop方法后数组arr1变成了23,42,12,我这里没有新建对象
按理arr1应该是不变化的啊,那为什么调用pop方法缺修改了arr1的值呢?
作者: 舒远    时间: 2012-9-7 20:00
concat 方法 (Array)
返回一个新数组,这个新数组是由两个或更多数组组合而成的。

pop 方法
移除数组中的最后一个元素并返回该元素。






欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2