黑马程序员技术交流社区
标题:
JavaScript中Array对象的一些方法问题
[打印本页]
作者:
黄树人
时间:
2012-9-7 19:36
标题:
JavaScript中Array对象的一些方法问题
<!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的值呢?
作者:
舒远
时间:
2012-9-7 20:00
concat 方法 (Array)
返回一个新数组,这个新数组是由两个或更多数组组合而成的。
pop 方法
移除数组中的最后一个元素并返回该元素。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2