How to Concat/Merge/Join Two Array in Javascript ES6

Let’s say, we have two arrays:

let arr1 = [1, 2, 3]
let arr2 = [5, 6, 7]

Now, you want to have a third array that merges the two arrays:

let arr3 = [1, 2, 3, 4, 5, 6]

To achieve that, you can simply destructure the two arrays and use the result to create another array like following:

let arr3 = [...arr1, ...arr2]
console.log(arr3)
[1, 2, 3, 4, 5, 6]

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.