六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 31|回复: 0

js concat方法

[复制链接]

升级  94.67%

52

主题

52

主题

52

主题

秀才

Rank: 2

积分
192
 楼主| 发表于 2013-1-29 09:01:21 | 显示全部楼层 |阅读模式
concat() 方法用于连接两个或多个数组。

该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本。

通过下面的例子很容易看明白:

<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
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表