Array concat()

In this chapter you will learn:

  1. How to add array together

Append array

The concat() method appends one array to another.

When no arguments are passed in, concat() clones the array and returns it. If one or more arrays are passed in, concat() concatenate the those arrays. If the values passed in are not arrays, they are simply appended to the end of the resulting array.

<!DOCTYPE html><!--  ja v  a2s  . c o m-->
<html>
<head>
    <script type="text/javascript">
        var colors = ["A", "B", "C"]; 
        var colors2 = colors.concat("D", ["E", "F"]); 
        document.writeln(colors); //A,B,C
        document.writeln(colors2); //A,B,C,D,E,F
       
    </script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. How to loop through array and work on each element in Javascript
Home » Javascript Tutorial » Array
Array Type
Array creation
Array type detecting
Array iterate
Array Length
Add to Array
Array join
Array concat()
Array every method
Array search from start with indexOf()
Array search from the end with lastIndexOf()
Array filter
Array mapping
Array forEach
Array pop and push
Array shift()
Array reduce()
Array reduceRight()
Array reverse()
Array slice()
Array some()
Array splice()
Array sort()
Array toString()
Array unshift()