Using concat() method to combine two arrays : Concat « Array « JavaScript Tutorial






<html>
<head>
<title>Using concat() method to combine two arrays</title>
<script type="text/javascript" language="javascript">
<!-- //
function ConcatArrays(){
var firstArray  = new Array(1,2,3);
var secondArray = new Array(4,5,6);
var combinedArray = firstArray.concat(secondArray);

var fa = firstArray.join(", ");
var sa = secondArray.join(", ");
var ca = combinedArray.join(", ");

document.write("<P>The first array contains: <b>" + fa + " </b></p>");
document.write("The second array contains: <b>" + sa + " </b></p>");
document.write("The combined array contains: <b>" + ca + " </b></p>");
document.write("The combined array length is: <b>" + combinedArray.length + "
</b></p>");
}
// -->
</script>
</head>
<body onload="ConcatArrays()">

</body>
</html>








11.9.Concat
11.9.1.Array.concat()
11.9.2.Actual success in copying an array using concat()
11.9.3.Using concat() method to combine two arrays