Alert generates the random value code in the array, and the alert array value code
Js Code
/** Then alert returns the array value * a, indicating the array */function alert1 (a) {var alength =. length; if (alength> 1) {var r = random1 (0, alength); alert (a [r]); a [r] =-1; var temp = Array (alength-1); var t = false; for (var I = 0; I <. length; I ++) {if (I = r) {t = true;} else {if (t = false) {temp [I] = a [I];} else {temp [I-1] = a [I] ;}} alert1 (temp );} else {alert (a [0]) ;}}
Js Code
/*** The value between min (inclusive) and max (excluded) */function random1 (min, max) {return Math. floor (min + (Math. random () * 10) % (max-min )));}
For js to loop out a set of data and assign it to an array, the last alert will output an array problem. The code for the array loop is as follows:
Var arr = new array ();
Changed:
Var arr = new Array ();
How does js determine whether a value is the first element in the array and generate the value alert. It is not a printing element, but a printing element.
<Script type = "text/javascript">
Function aa (){
Var mycars = new Array ();
Mycars [0] = "aaa ";
Mycars [1] = "bbb ";
Mycars [2] = "ccc ";
// Ie does not support the indexOf method. The following if code is compatible with ie.
If (! Array. indexOf ){
Array. prototype. indexOf = function (obj ){
For (var I = 0; I <this. length; I ++ ){
If (this [I] = obj ){
Return I;
}
}
Return-1;
}
}
Var a = mycars. indexOf ('bbb ');
// The array starts from 0, so the element position is equal to the return value + 1. If it is too troublesome, use var a = mycars. indexOf ('bbb ') + 1; then the returned value is its position.
Alert ();
}
Window. onload = aa;
</Script>
Try it !!!