title: Google Sheets Script Error - Cannot convert Array to Object[][]
body: <p>I'm working on a script to encode data in fields for insertion into HTML (the cells contain words like <code>Planétarium</code> and <code>Rua João Bettega, 01</code>). I am getting an error and don't know what to do with it. The error says <strong>"Cannot convert Array to Object[][]"</strong></p>
  
  <p>I'm definitely passing a two-dim array to <code>.setValues()</code>, so I know that's not it (found that to be a common problem). Any ideas? Here's my function:</p>
  
  <pre><code>// columns[] and columns2encode[] are set in the scope above this function
  function _encodeData() {
    var sheet = _getSheet();
    var data = sheet.getDataRange().getValues();
    var rowCnt = data.length;
    var colCnt = data[0].length;
    var data2set = new Array(rowCnt-1); // creates array w/ row.length indeces
    var colEncodeIndexList = [];
    var origVal, encodedVal, range, cell; // used later in for loop(s)
  
    toast('Start Encoding Data');
  
    // loop every row
    for(var ri = 0; ri &lt; data.length; ri++) {
      if(ri !== 0) {
        data2set[ri] = new Array(colCnt); // creates array w/ length of ~ 29
      }
  
      // loop every cell (column entry in the given row)
      for(var ci = 0; ci &lt; data[ri].length; ci++) {
        // get text content of current cell
        origVal = data[ri][ci];
  
        // if first row, headers - save matches in array for later
        if(ri === 0) { // I split the ifs so inArray isn't called EVERY time
          if(inArray(columns2encode, origVal)) { // add col header if "on the list"
            colEncodeIndexList.push(ci);
          }
        } else { // isn't the header row
          // if ! first row, values - col num must be in saved headers to encode OR it's a number
          if(!inArray(colEncodeIndexList, ci) || typeof origVal === 'number') {
            // just use origVal
            data2set[ri][ci] = origVal;
          } else {
            // use encodedVal
            encodedVal = _htmlEncode(origVal);
  
            data2set[ri][ci] = encodedVal;
          }
        } // else
      } // for (cells/cols)
    } // for (rows)
  
    // Now pass array of arrays (data) to setValues()
    var setRange = sheet.getRange(2, 1, (data.length-1), data[0].length);//.getA1Notation(); // starts at 2, 1 (row 2, col 1) to ignore column header
    setRange.setValues(data2set);
  
    toast('Finished Encoding Data');
  }
  </code></pre>
  
  <p>Thanks in advance!</p>