How to append an array to another in JavaScript ?

Published on June 20, 2016 by abundantcode

Filed under JavaScript

Last modified June 20, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 1.5 (2 votes)

This article have been viewed 5010 times

In JavaScript , you may want to append one array to another array(s) to combine their elements resulting in to a single array.

How to append an array to another in JavaScript ?

You can use the concat method of JavaScript to achieve the same. Below is a sample code snippet demonstrating the usage of the concat method of array in JavaScript to combine multiple arrays.

<html>
<head>
    <script type="text/javascript">       
        var inputArray1 = ['abundant', 'code'];
        var inputArray2 = ['.', 'com'];
        var inputArray3 = [' website'];
        var ConcatenatedOutputString = inputArray1.concat(inputArray2, inputArray3);
        console.log(ConcatenatedOutputString);
    </script>
</head>
<body>
</body>
</html>

image

Leave a Comment


x

You might be Interested in these Posts

C# Program to swap two numbers without using temporary variable

Problem Write a program in Visual CSharp to swap two numbers using temporary variable and display t...

C# Program to swap two numbers

Problem Write a program in C# to swap two numbers using temporary variable and display the result i...

C# Program to print the sum of two numbers

Problem Write a program in C# to add two numbers and display the result in copnsole window. How to...