There are several ways to concatenate two string arrays in JavaScript.

One way is to use the concat() method. For example:

var arr1 = ["apple", "banana"];
var arr2 = ["cherry", "date"];
var newArr = arr1.concat(arr2);
console.log(newArr); // ["apple", "banana", "cherry", "date"]

Another way is to use the spread operator (…). For example:

var arr1 = ["apple", "banana"];
var arr2 = ["cherry", "date"];
var newArr = [...arr1, ...arr2];
console.log(newArr); // ["apple", "banana", "cherry", "date"]

You can also use a for loop to iterate through the second array and push each element to the first array.

var arr1 = ["apple", "banana"];
var arr2 = ["cherry", "date"];
for (var i = 0; i < arr2.length; i++) {
    arr1.push(arr2[i]);
}
console.log(arr1); // ["apple", "banana", "cherry", "date"]

You can also use forEach method to iterate through the second array and push each element to the first array.

var arr1 = ["apple", "banana"];
var arr2 = ["cherry", "date"];
arr2.forEach(function(item) {
    arr1.push(item);
});
console.log(arr1); // ["apple", "banana", "cherry", "date"]

Please note that all the above methods will change the original array (arr1) and return a new concatenated array.

You can use any of the above methods to concatenate two arrays of strings and get the desired result.

Also Read:

Categorized in: