当前位置: 首页 > 网络学院 > 客户端脚本教程 > JavaScript > JavaScript concat() 方法
The concat() method is used to join two or more arrays.
使用concat()方法可用来将两个或多个数组结合起来
This method does not change the existing arrays, it only returns a copy of the joined arrays.
这个方法不会改变现存的数组,它只返回了所结合数组的一份拷贝。
arrayObject.concat(arrayX,arrayX,......,arrayX) |
Parameter 参数 | Description 描述 |
---|---|
arrayX | Required. One or more array objects to be joined to an array 必选项。一个或多个数组组合成一个数组 |
Here we create two arrays and show them as one using concat():
这里我们使用了concat()将两个数组结合成了一个:
<script type="text/javascript"> var arr = new Array(3) var arr2 = new Array(3) document.write(arr.concat(arr2)) </script> |
The output of the code above will be:
上面代码的输出结果为:
Jani,Tove,Hege,John,Andy,Wendy |
Here we create three arrays and show them as one using concat():
我们通过使用concat()将三个数组结合成为了一个数组:
<script type="text/javascript"> var arr = new Array(3) var arr2 = new Array(3) var arr3 = new Array(2) document.write(arr.concat(arr2,arr3)) </script> |
The output of the code above will be:
上面代码的结果为:
Jani,Tove,Hege,John,Andy,Wendy,Stale,Borge |
How to join two arrays with the concat() method
怎样通过concat()方法结合两个数组
How to join three arrays with the concat() method
怎样使用concat()方法结合三个数组