- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>练习</title>
- </head>
- <body>
- <script type="text/javascript">
- //Array对象
- var arr1=[23,42,12,29];
- var arr2=[21,53];
- var length=arr1.length;
- document.write("数组的长度是:"+length+"<br/>");
- document.write("concat后的数组为:"+arr1.concat(arr2)+"<br/>");
- document.write("join后的数组为:"+arr1.join("-")+"<br/>");
- document.write("pop数组:"+arr1.pop()+"<br/>");
- document.write("pop后的数组为:"+arr1+"<br/>");
-
- </script>
- </body>
- </html>
复制代码 在Array对象中定义了2个数组,调用concat方法把2个数组连起来
输出结果为23,42,12,29,21,53,但arr1数组还是没变,
可调用pop方法后数组arr1变成了23,42,12,我这里没有新建对象
按理arr1应该是不变化的啊,那为什么调用pop方法缺修改了arr1的值呢? |