Return to Kroll Web Design home page JavaScript

« Return

concat method for arrays

The concat method joins multiple arrays into one new array.

Code:

<script type="text/javascript">
//<![CDATA[
array1 = new Array("triangle", "circle", "square"); array2 = new Array("rectangle", "pentagon", "hexagon"); shapes = array1.concat(array2); for (i=0; i<array1.length; i++) { document.write("array1[", i, "] : ", array1[i], "<br>"); } document.write("<br>"); for (i=0; i<array2.length; i++) { document.write("array2[", i, "] : ", array2[i], "<br>"); } document.write("<br>"); for (i=0; i<shapes.length; i++) { document.write("shapes[", i, "] : ", shapes[i], "<br>"); } //]]> </script>

Output:




©2010 Kroll Web Design    davidarthurkroll@verizon.net    781.910.3694

Valid XHTML 1.0 Transitional Valid CSS!