Home > front end >  Js two-dimensional array is undefined after assignment
Js two-dimensional array is undefined after assignment

Time:12-22

 function GAInitPop () {
Chrom=new Array ();

For (var ik=0; Ik<10; Ik++) {//one dimension length is
Chrom1 [ik]=randperm (7);
The console. The log (Chrom (ik));
}

The console. The log (Chrom);
Return Chrom
}


//set up from 1 to integer array and random sequence arrangement of num
The function randperm (num) {
Var randarr=new Array ();
For (var ir=0; The ir & lt; Num. Ir + +) {
Randarr] [ir=ir + 1;
}
Randarr. Shuffle ();
Return randarr;
}



//Array shuffle
Array. The prototype. Shuffle=function () {
Var j, TMP, I;
For (I=this. Length - 1. I> 0; I -) {
J=parseInt (Math. The random () * I);
TMP=this [I];
This [I]=this [j];
This [j]=TMP;
}

}

Chrom=GAInitPop ();
The console. The log (Chrom)


I hope to get a 10 lines 7 column two-dimensional array
In a separate test can get, but in other features of web pages there will be only the last line of data, like the picture
why?

CodePudding user response:

Look at page other function code is also made from the Chrom global variables,
Is not recommended to js built-in objects, using the method of the prototype to add custom which may affect other functions with page code,
To shuffle into ordinary functions,

  • Related