从数组中计数信息时,实际结果为-1

时间:2019-04-01 05:25:36

标签: javascript loops

我正在从在线报告中获取电子表格,该文件是我格式化的CSV文件,因此可以被gscript使用。

因此,我正在循环并使用数组来计数大于0的所有值。但是当将信息显示为少一个值时...那么假设工作表上有7个值,记录器将显示6个...我对此非常陌生,所以我将不胜感激。

佣金变量是有问题的那个

function start()
{
    var startDate = new Date();
    var endDate = new Date();   

    var sMonth = startDate.getMonth()+1; //start day variables
    var sDay = startDate.getDate()-3;
    var sYear = startDate.getFullYear();

    startDate = sMonth+"-"+sDay+"-"+sYear; //concatenate date
    endDate = startDate;

    var csvUrl = "http://publisherpro.flexoffers.com/Report/Public?gui=9ce2029a-e14c-4548-a1af-0f0e2e8894c8&d1=" +startDate+"&d2="+endDate+ "&t=A&o=CSV"

    Logger.log(csvUrl);

    var csvContent = UrlFetchApp.fetch(csvUrl).getContentText(); // 
    Just formating the file to be useable within Google Scripts
    var csvData = Utilities.parseCsv(csvContent); // Same as above //Returns a tabular 2D array representation of a CSV string.

    var counter = new Array;
    var commision = 0;
    for (var c = 2; c < csvData.length; c++) {

      if (csvData[c][21] > 0) 
      {
        commision++
      }
      }
      Logger.log(commision)
}

0 个答案:

没有答案