开发者

How can I add additional elements to my array?

I was trying to get the country name and put it in the temparray, so that I can use the temparray to check the country (line 14). The problem is temparray can only contain one value and upon increasing the array length size by using temparray.length = 4, the heat map won't show up in the page.

The code below is to check duplicate name entry fro开发者_运维知识库m within the array. If the country name is repeated, it will add the past value and its current value and add it into the data table again as the old row.

      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/>");
        }
     }

     }


I don't really understand what you are trying to do with temparray. It can surely contain more than one element with a temparray.push(countryname). Maybe this JavaScript array reference will help you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜