JavaScript Array concat() Method
You are Here:
JavaScript Array concat() Method
The concat()
method is used to join two or more arrays.
Note: This method does not alter the existing arrays, but returns a new array, containing the values of the joined arrays.
Concatenating Two Arrays
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var set1 = ["One", "Two"];
var set2 = ["Three", "Four"];
var result = [];
// Concatenate two arrays
result = set1.concat(set2);
document.write(result);
</script>
</body>
</html>
Syntax
Array1.concat(array2, array3, ...., arrayN)
Parameter Values
Value | Type | Explanation |
---|---|---|
array2..arrayN | Required | Arrays to concatenate into a new array. |
Concatenating More than Two Arrays
Note: Use comma-separator when joining more than two arrays.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<script>
var set1 = ["One", "Two"];
var set2 = ["Three", "Four"];
var set3 = ["Five", "Six"];
var result = [];
// Concatenate multiple arrays
result = set1.concat(set2, set3);
document.write(result);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.