---
title: "Merge two arrays in jQuery"  
description: "Merge two arrays in jQuery"  
author: "Ethan Karla"  
published: 2021-07-29  
updated: 2023-06-14  
canonical: https://www.mindstick.com/forum/156673/merge-two-arrays-in-jquery  
category: "jquery"  
tags: ["jquery"]  
reading_time: 1 minute  

---

# Merge two arrays in jQuery

How to [merge](https://www.mindstick.com/startup/15/how-growthpal-helps-companies-make-the-right) [two arrays](https://www.mindstick.com/forum/161074/how-to-compare-two-arrays-to-each-other-in-javascript) in jQuery?

## Replies

### Reply by Aryan Kumar

Sure, here is how to [merge two](https://www.mindstick.com/forum/23218/merge-two-python-dictionaries-in-a-single-expression) [arrays](https://www.mindstick.com/articles/11955/arrays-and-its-limitations) in jQuery:

Code snippet

```plaintext
// Define two arrays
var arr1 = [1, 2, 3];
var arr2 = [4, 5, 6];

// Merge the arrays
var mergedArray = $.merge(arr1, arr2);

// Print the merged array
console.log(mergedArray);
```

This will print the following output:

Code snippet

```plaintext
[1, 2, 3, 4, 5, 6]
```

As you can see, the mergedArray variable now contains all of the elements from both arr1 and arr2.

Here is a breakdown of what the code is doing:

- The <span class="math-inline">\.merge\(\)\ method is used to merge two arrays. * The `arr1` and `arr2` variables are passed to the `.merge()` method as arguments.
- The <span class="math-inline">\.merge\(\)\ method returns a new array that contains all of the elements from both `arr1` and `arr2`. * The `mergedArray` variable is assigned the value returned by the `.merge()` method.
- The console.log() function is used to print the value of the mergedArray variable.


---

Original Source: https://www.mindstick.com/forum/156673/merge-two-arrays-in-jquery

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
