concat() 方法用于连接两个或多个数组。
该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本。
通过下面的例子很容易看明白:
结果:
tempList:a
tempList:b
tempList:c
tempList:d
tempList2:e
tempList2:f
tempList2:g
tempList2:h
tempList3:a
tempList3:b
tempList3:c
tempList3:d
tempList3:e
tempList3:f
tempList3:g
tempList3:h
该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本。
通过下面的例子很容易看明白:
<script language="JavaScript" type="text/javascript">
var tempList = new Array();
tempList[0] = "a";
tempList[1] = "b";
tempList[2] = "c";
tempList[3] = "d";
var tempList2 = new Array();
tempList2[0] = "e";
tempList2[1] = "f";
tempList2[2] = "g";
tempList2[3] = "h";
var tempList3 = new Array();
tempList3 = tempList.concat(tempList2);
for(var i = 0; i < tempList.length; i++) {
document.write("tempList:" + tempList[i] + "<br>");
}
for(var i = 0; i < tempList2.length; i++) {
document.write("tempList2:" + tempList2[i] + "<br>");
}
for(var i = 0; i < tempList3.length; i++) {
document.write("tempList3:" + tempList3[i] + "<br>");
}
</script>
结果:
tempList:a
tempList:b
tempList:c
tempList:d
tempList2:e
tempList2:f
tempList2:g
tempList2:h
tempList3:a
tempList3:b
tempList3:c
tempList3:d
tempList3:e
tempList3:f
tempList3:g
tempList3:h
6523

被折叠的 条评论
为什么被折叠?



