Home >>JavaScript Array Reference >JavaScript Array concat() Method
Array concat() method is used to creates a new array consisting of the elements in the object. By using this method, you can merge two or more arrays together. This method does not change the original arrays passed as arguments.
Syntax:
var new_array = old_array.concat(value1[, value2[, ...[, valueN]]])
Parameter | Description |
---|---|
array2, array3, ..., arrayX | It Required the arrays to be joined |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
concat() | 1.0 | 5.5 | 1.0 | Yes | Yes |
Here is an example of JavaScript array concat() Method:
<html> <body> <button onclick="myconcate()">click me</button> <p id="concat"></p> <script> function myconcate() { var x = ["red", "blue"]; var y = ["yellow", "green", "orange"]; var children = x.concat(y); document.getElementById("concat").innerHTML = children; } </script> </body> </html>
Example 2:
<html> <body> <script> function concate() { var alpha = ['a', 'b', 'c']; document.write(alpha.concat(1, [2, 3])); } concate(); </script> </body> </html>