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>
<html>
<body>
<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>
<script>
function concateTwoArray() {
var twoDay= ["Sunday", "Monday"];
var fiveDay= ["Tuesday", "Wednsday","Thursday", "Friday","Saturday"];
var totalDay = twoDay.concat(fiveDay);
document.getElementById("pId").innerHTML = totalDay ;
}
</script>
</body>
</html>

One thought on “JavaScript concate or merge two Arrays

  • December 23, 2021 at 1:35 pm
    Permalink

    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.

    Reply

Leave a Reply

Your email address will not be published.