Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

Today, we will learn to append an array to another array in javascript, here we will use the array concat() method to merge two arrays.

The concat() method

The concat() method is used to merge two or more arrays. This method does not change the existing arrays but instead returns a new array.

– MDN

So, here we will create two sample arrays like the below example, after that, we will use concat() method to append one array to another, and store it in the third array variable.

// create sample arrays
const arr1 = ['a', 'b', 'c'];
const arr2 = ['d', 'e', 'f'];

// apend array 
const arr3 = arr1.concat(arr2);

console.log(arr3);

when you run the above code, it will concat both array and print in your console.

let’s check the output.

javascript, append an array to another array example
javascript, append an array to another array example

I hope it’s help you, All the best 👍.