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
分享到:
相关推荐
1.concat方法的基础介绍 2.从实例中感受concat方法 1.concat方法的基础介绍 concat方法用于多个数组的合并。它将新数组的成员,添加到原数组的尾部,然后返回一个新数组,原数组不变。 console.log([].concat([1],...
JavaScript concat 方法 concat 方法连接两个或多个字符串,其语法如下: 代码如下: str_object.concat(str1, str2, …) str_object 是需要连接的第一个字符串(对象),str1 是需要连接的第二个字符串,str2 是...
这篇文章主要介绍了JavaScript的concat方法实例代码,包括数组连与字符连接,需要的朋友可以参考下
1.concat方法的基础介绍 2.从实例中感受concat方法 1.concat方法的基础介绍 concat方法用于多个数组的合并。它将新数组的成员,添加到原数组的尾部,然后返回一个新数组,原数组不变。 console.log([].concat...
没有给concat方法传递参数的情况下,它只是复制当前数组并返回副本。 如果传递的是一或多个数组,则该方法会将这些数组中的每一项都添加到结果数组中 如果传递的值是不是数组,这些值会被简单的添加到数组的...
js代码-js concat 数组合并 数组连接
这篇文章主要介绍了JS合并两个数组的3种方法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,...这里有一个问题,concat方法连接a、b两个数组后,a、b两个数组的数据不变,同时会返
本文实例讲述了JavaScript使用concat连接数组的方法。分享给大家供大家参考。具体如下: 下面的代码演示了JS中如何通过concat函数链接多个数组 <!DOCTYPE html> <html> <body> [removed] var ...
在本篇文章里小编给大家总结了关于JavaScript中concat复制数组方法知识点,有需要的朋友们可以学习下。
concat() 方法用于连接两个或多个数组。 该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本。 语法 arrayObject.concat(arrayX,arrayX,......,arrayX) 参数 描述 arrayX 必需。该参数可以是具体的...
JS 数组的 push 与 concat 区别 值得看看
[removed] /* 数组的concat()方法: 1、该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本。 2、返回一个新的数组。该数组是通过把所有 arrayX 参数添加到 arrayObject 中生成的。 如果要进行 concat() ...
主要介绍了js采用concat和sort将N个数组拼接起来的方法,涉及JavaScript针对数组的合并与排序操作相关技巧,需要的朋友可以参考下
浅谈JavaScript的push(),pop(),concat()方法_.docx
主要介绍了JavaScript中使用concat()方法拼接字符串的教程,是JS入门学习中的基础知识,需要的朋友可以参考下
concat-stream - 连接一个流成字符串或二进制数据
js代码-JavaScript(js) concat() 用法