Ask Your Question

Revision history [back]

You can use a for loop to apply the values of a 1x6 array to an _x6 array in Google App Script. Here is an example code:

function applyValues() {
  var sourceArray = [1, 2, 3, 4, 5, 6]; // 1x6 array
  var targetArray = [['', '', '', '', '', ''], ['', '', '', '', '', '']]; // _x6 array

  for (var i = 0; i < sourceArray.length; i++) {
    for (var j = 0; j < targetArray.length; j++) {
      targetArray[j][i] = sourceArray[i]; // assign each value from source array to each row in the target array
    }
  }

  Logger.log(targetArray); // log the target array to check the result
}

In this example, the sourceArray is a 1x6 array and the targetArray is a 2x6 array (with 2 rows and 6 columns). The goal is to apply the values of the sourceArray to all rows of the targetArray (in the same column).

To do this, we use a nested for loop where the outer loop iterates over the values of the sourceArray, and the inner loop iterates over the rows of the targetArray. Then, we assign each value from sourceArray to the corresponding element of the targetArray (using the same column index i). Finally, we log the target array to check the result.

Note that this code assumes that the size of the targetArray is known (in this case, 2x6). If the size of the targetArray is not known, you can use the push() method to add each row dynamically.