JavaScript concate or merge two Arrays

Now we will see how we can concate or merge two arrays in JavaScript by using the concat() method.

Here I have two arrays like:

var twoDay= [“Sunday”, “Monday”]; var fiveDay= [“Tuesday”, “Wednsday”,”Thursday”, “Friday”,”Saturday”];

Below is the JavaScript code which will concat both the arrays.

<!DOCTYPE html>
<p>We will see after clicking the button how two array will join</p>
<button onclick="concateTwoArray()" id="btnClick">Click</button>
<p id="pId"></p>
function concateTwoArray() {
var twoDay= ["Sunday", "Monday"];
var fiveDay= ["Tuesday", "Wednsday","Thursday", "Friday","Saturday"];
var totalDay = twoDay.concat(fiveDay);
document.getElementById("pId").innerHTML = totalDay ;

One thought on “JavaScript concate or merge two Arrays

  • December 23, 2021 at 1:35 pm

    We’re a group of volunteers and opening a new scheme in our community. Your website offered us with valuable information to work on. You have done a formidable job and our whole community will be grateful to you.


Leave a Reply

Your email address will not be published. Required fields are marked *