js concat方法

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值