How to Merge Two Array in JavaScript | Step by Step Guide

How to Merge Two Array in JavaScript

Learn how to merge two array in javascript with these simple steps.

1. Creating an array

To create an array in javascript, we need to use the “const” or “var” keyword then we give array name and assigned the array values within the square brackets [ ]. So, here we have created two arrays.


const Fruits = ["Apple", "Orange", "banana"];
const Vegitables = ["Onion", "Tomato", "Beans", "Potato"];

2. Merging two arrays

To merge the two lists of array values, we need to use “concat()” method in . Concat() returns a new array by concatenating/appending given element(s) to the elements of the given array.


concat(..args): Arrays

…args = indicates elements to be concatenated/appended


const shop = Fruits.concat(Vegitables);

Here, I merged the Fruits and Vegetables array using concat() method and store it as “shop” variable.
Then printed the “shop”. See the output, the two arrays is merged and displayed.


merge two array in javascript

Leave a Reply