Alert generates the random value code in the array, and the alert array value code

Source: Internet
Author: User

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 !!!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.