How To Add values to two-dimensional array with for loops using Google Apps Script

前端 未结 1 1109
我在风中等你
我在风中等你 2021-01-21 17:59

Could someone show me some simple examples to add values with for loops to a two-dimensional array?

My totally wrong test script is below.

Expected behav

相关标签:
1条回答
  • 2021-01-21 18:27

    Hope this could help.

    function test() {
    
      //2d array
      var wholeValues = [];
    
    
      for (var i = 0; i < 5; i++){  
    
        //create a 1D array first with pushing 0,1,2 elements with a for loop
        var value = [];
        for (var j = 0; j < 3; j++) {           
          value.push(j);
        }
        //pushing the value array with [0,1,2] to thw wholeValues array. 
        wholeValues.push(value);
      } // the outer for loop runs five times , so five the 0,1,2 with be pushed in to thewholevalues array by creating wholeValues[0][0],wholeValues[0][1]...till..wholeValues[4][2]
    
      Logger.log(wholeValues[0][1]);
    }
    
    0 讨论(0)
提交回复
热议问题