如何添加额外的元素到我的数组

How can I add additional elements to my array?

本文关键字:元素 我的 数组 何添加 添加      更新时间:2023-09-26

我试图获得国家名称并将其放在temparray中,以便我可以使用temparray来检查国家(第14行)。问题是temparray只能包含一个值,并且通过使用temparray增加数组长度大小。长度= 4,热图将不会显示在页面上。

下面的代码用于检查数组中重复的名称条目。如果国家名称重复,它将添加过去值和当前值,并将其作为旧行再次添加到数据表中。

      var i;
      var suq = 0;
      var temparray = [""];
      var rowcount= 0;
     //set the value
     for (i = 0; i<count; i++){
        var countryname = countryarray[i];
        var hostcount = hosthitcount[i];
        //document.write("hello");
            for (rowcount=0;rowcount<temparray.length;rowcount++){
               //check for any repeated country name
             if (temparray[rowcount] != countryname){
                 data.setValue(suq, 0, countryname);
                 data.setValue(suq, 1, hostcount);
                 temparray[rowcount] = countryname;
               //document.write("win");document.write("<br/>");
                 suq++;
        }else{
                  //get the hits                //rowindex
                  var pastvalue = data.getValue(rowcount,1);
                  //add the previous value with current value
                  var value = parseInt(hostcount)+parseInt(pastvalue);
                  value+= "";
                  //document.write(value);
                  //put it in the table
                 data.setValue(rowcount,1,value);
                 // document.write("lose");document.write("<br/>");
        }
     }
     }

我真的不明白你想用temparray做什么。它当然可以包含不止一个具有temparray.push(countryname)的元素。也许这个JavaScript数组引用会对你有所帮助?