Concat Function ()

In Google Apps Script, the concat() method is an array method that allows you to join two or more arrays into a single array. It creates a new array that contains the elements of the original arrays in the order they were passed as arguments.

Here is an example of using the concat() method to join two arrays of country names:

var countries1 = ["USA", "Canada", "Mexico"];
var countries2 = ["Brazil", "Argentina"];

// Join the countries1 and countries2 arrays into a single array
var allCountries = countries1.concat(countries2);

// Output the new array
Logger.log(allCountries); // Outputs: ["USA", "Canada", "Mexico", "Brazil", "Argentina"]

In this example, we call the concat() method on the countries1 array, passing the countries2 array as an argument. The result is a new array, allCountries, that contains all the elements of the countries1 and countries2 arrays in the order they were passed as arguments. The new array is outputted to the log using the Logger.log() method.

You can also use the concat() method to join more than two arrays:

var numbers1 = [1, 2, 3];
var numbers2 = [4, 5];
var numbers3 = [6, 7, 8];

// Join the numbers1, numbers2, and numbers3 arrays into a single array
var allNumbers = numbers1.concat(numbers2, numbers3);

// Output the new array
Logger.log(allNumbers); // Outputs: [1, 2, 3, 4, 5, 6, 7, 8]

In this example, we call the concat() method on the numbers1 array, passing the numbers2 and numbers3 arrays as additional arguments. The result is a new array, allNumbers, that contains all the elements of the numbers1, numbers2, and numbers3 arrays in the order they were passed as arguments. The new array is outputted to the log using the Logger.log() method.